From d713e9f202663cdebbe47c1d0843f25a3d16930d Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Fri, 21 Aug 2020 15:04:16 -0700 Subject: [PATCH] Prevent call objects from outliving its parent channel or server --- src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi | 2 ++ src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi index bfbcb8d4fc8..10c024e1b39 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi @@ -46,6 +46,7 @@ cdef class _AioCall(GrpcCallWrapper): def __cinit__(self, AioChannel channel, object deadline, bytes method, CallCredentials call_credentials, object wait_for_ready): + init_grpc_aio() self.call = NULL self._channel = channel self._loop = channel.loop @@ -63,6 +64,7 @@ cdef class _AioCall(GrpcCallWrapper): def __dealloc__(self): if self.call: grpc_call_unref(self.call) + shutdown_grpc_aio() def _repr(self) -> str: """Assembles the RPC representation string.""" diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi index 760fef91cf0..a630ed88117 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi @@ -45,6 +45,7 @@ class _ServerStoppedError(BaseError): cdef class RPCState: def __cinit__(self, AioServer server): + init_grpc_aio() self.call = NULL self.server = server grpc_metadata_array_init(&self.request_metadata) @@ -106,6 +107,7 @@ cdef class RPCState: grpc_metadata_array_destroy(&self.request_metadata) if self.call: grpc_call_unref(self.call) + shutdown_grpc_aio() cdef class _ServicerContext: