Skip to content

Regression: Calling an unimplemented method causes a traceback to be emitted to stderr in the server process #34853

@justinvp

Description

@justinvp

What version of gRPC and what language are you using?

grpcio==1.58.0

Python

What operating system (Linux, Windows,...) and version?

macOS 12.6.6

What runtime / compiler are you using (e.g. python version or version of gcc)

Python 3.10.6

What did you do?

We have a server that implements a gRPC service in Python. It contains a method that is deliberately unimplemented. The unimplemented method uses the standard implementation for unimplemented methods:

class MyResourceProviderServicer(provider_pb2_grpc.ResourceProviderServicer):
    def __init__(self):
        pass

    def DiffConfig(self, request, context):
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

Clients that call this method are resilient to it being implemented or not.

When the server is running with grpcio>=1.58.0 and the unimplemented method is called, a traceback is emitted to stderr:

Traceback (most recent call last):
  File "/Users/justin/go/src/github.com/justinvp/grpc-python-repro/venv/lib/python3.10/site-packages/grpc/_server.py", line 552, in _call_behavior
    response_or_iterator = behavior(argument, context)
  File "/Users/justin/go/src/github.com/justinvp/grpc-python-repro/provider_pb2_grpc.py", line 31, in DiffConfig
    raise NotImplementedError('Method not implemented!')
NotImplementedError: Method not implemented!

When the server is running with grpcio<=1.57.0 and the unimplemented method is called, the server does not emit anything, which is the behavior we expect: Nothing emitted to stderr.

We don't want the server to emit the traceback because our client redirects the server process's stdout and stderr and displays those to users. Calling an unimplemented method should not result in a traceback being emitted.

It looks like this behavior change was introduced in #33442

This is blocking us from supporting Python 3.12, which requires the use of grpcio 1.59.0.

I've prepared a minimal example repro with steps at https://github.com/justinvp/grpc-python-repro

What did you expect to see?

Expected no traceback to be emitted to stderr.

What did you see instead?

A traceback was emitted to stderr.

Traceback (most recent call last):
  File "/Users/justin/go/src/github.com/justinvp/grpc-python-repro/venv/lib/python3.10/site-packages/grpc/_server.py", line 552, in _call_behavior
    response_or_iterator = behavior(argument, context)
  File "/Users/justin/go/src/github.com/justinvp/grpc-python-repro/provider_pb2_grpc.py", line 31, in DiffConfig
    raise NotImplementedError('Method not implemented!')
NotImplementedError: Method not implemented!

Anything else we should know about your project / environment?

Downstream issue: pulumi/pulumi#14442

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions