Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRpc client interceptor throws uncatchable exception when rpc is cancelled #790

Open
z-oo opened this issue Sep 20, 2019 · 0 comments
Open
Labels

Comments

@z-oo
Copy link

z-oo commented Sep 20, 2019

Describe your environment. Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on master.

Python version: 2.7
Code built under bazel 0.28.1

Steps to reproduce.

  1. Send an opencensus instrumented grpc
  2. cancel the grpc
  3. client side application crashes and a stacktrace like this:
Traceback (most recent call last):
    File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
        self.run()
      File "/usr/lib/python2.7/threading.py", line 754, in run
        self.__target(*self.__args, **self.__kwargs)
      File "/home/hlightman/worktrees/scene-finder-profile/bazel-bin/tool/scene_finder/query/server/query_server.runfiles/pip_deps/grpc/_channel.py", line 701, in channel_spin
        completed_call = event.tag(event)
      File "/home/hlightman/worktrees/scene-finder-profile/bazel-bin/tool/scene_finder/query/server/query_server.runfiles/pip_deps/grpc/_channel.py", line 174, in handle_event
        callback()
      File "/home/hlightman/worktrees/scene-finder-profile/bazel-bin/tool/scene_finder/query/server/query_server.runfiles/pip_deps/grpc/_channel.py", line 313, in <lambda>
        self._state.callbacks.append(lambda: fn(self))
      File "/home/hlightman/worktrees/scene-finder-profile/bazel-bin/tool/scene_finder/query/server/query_server.runfiles/pip_deps/opencensus/ext/grpc/client_interceptor.py", line 131, in callback
        proto_message=future_response.result(),
          File "/home/hlightman/worktrees/scene-finder-profile/bazel-bin/tool/scene_finder/query/server/query_server.runfiles/pip_deps/grpc/_channel.py", line 277, in result
        raise grpc.FutureCancelledError()
    FutureCancelledError

Please notice that here the exception is thrown from a thread that is not owned by the application and is impossible to catch.

What is the expected behavior?
No exception and rpc cancellation is correctly recorded by opencensus.

What is the actual behavior?
An uncaught exception is thrown from grpc thread. Please see above.

Additional context.
The bug is very likely from here:

    def _callback(self, current_span):
        def callback(future_response):
            grpc_utils.add_message_event(
                proto_message=future_response.result(),
                span=current_span,
                message_event_type=time_event.Type.RECEIVED,
            )
            self._trace_future_exception(future_response)
            self.tracer.end_span()

        return 

The first future_response.result() causes the exception to raise, and the second line self._trace_future_exception(future_response) has no chance to be executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant