diff options
author | Masood Malekghassemi <atash@google.com> | 2016-12-15 11:16:50 -0800 |
---|---|---|
committer | Masood Malekghassemi <atash@google.com> | 2017-01-23 15:10:27 -0500 |
commit | 0b1bb2d418d5782c8e527d2f2034dee9143b0bfb (patch) | |
tree | 97331c7acc64bf18bf9fa6f3f4534c75153859ac | |
parent | ba9aa59bdfc107054dd6083f36b3527a9bc85d72 (diff) |
Don't leak Py exceptions without calling gRPC core
-rw-r--r-- | src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index 04872b9c09..4d988192df 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -29,6 +29,8 @@ cimport cpython +import traceback + cdef class ChannelCredentials: @@ -138,15 +140,22 @@ cdef class AuthMetadataContext: cdef void plugin_get_metadata( void *state, grpc_auth_metadata_context context, grpc_credentials_plugin_metadata_cb cb, void *user_data) with gil: + called_flag = [False] def python_callback( Metadata metadata, grpc_status_code status, bytes error_details): cb(user_data, metadata.c_metadata_array.metadata, metadata.c_metadata_array.count, status, error_details) + called_flag[0] = True cdef CredentialsMetadataPlugin self = <CredentialsMetadataPlugin>state cdef AuthMetadataContext cy_context = AuthMetadataContext() cy_context.context = context - self.plugin_callback(cy_context, python_callback) + try: + self.plugin_callback(cy_context, python_callback) + except Exception as error: + if not called_flag[0]: + cb(user_data, Metadata([]).c_metadata_array.metadata, + 0, StatusCode.unknown, traceback.format_exc().encode()) cdef void plugin_destroy_c_plugin_state(void *state) with gil: cpython.Py_DECREF(<CredentialsMetadataPlugin>state) |