Ensure channel isolation is maintained while graceful close

pull/21988/head
Lidi Zheng 5 years ago
parent 5a29f33a25
commit e0f8fe3254
  1. 2
      src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pxd.pxi
  2. 10
      src/python/grpcio/grpc/experimental/aio/_channel.py
  3. 12
      src/python/grpcio_tests/tests_aio/unit/close_channel_test.py

@ -15,7 +15,7 @@
cdef class _AioCall(GrpcCallWrapper): cdef class _AioCall(GrpcCallWrapper):
cdef: cdef:
AioChannel _channel readonly AioChannel _channel
list _references list _references
object _deadline object _deadline
list _done_callbacks list _done_callbacks

@ -61,11 +61,6 @@ class _BaseMultiCallable:
Handles the initialization logic and stores common attributes. Handles the initialization logic and stores common attributes.
""" """
_loop: asyncio.AbstractEventLoop _loop: asyncio.AbstractEventLoop
_channel: cygrpc.AioChannel
_method: bytes
_request_serializer: SerializingFunction
_response_deserializer: DeserializingFunction
_channel: cygrpc.AioChannel _channel: cygrpc.AioChannel
_method: bytes _method: bytes
_request_serializer: SerializingFunction _request_serializer: SerializingFunction
@ -368,8 +363,9 @@ class Channel:
candidate = frame.f_locals.get('self') candidate = frame.f_locals.get('self')
if candidate: if candidate:
if isinstance(candidate, _base_call.Call): if isinstance(candidate, _base_call.Call):
calls.append(candidate) if candidate._cython_call._channel is self._channel:
call_tasks.append(task) calls.append(candidate)
call_tasks.append(task)
# If needed, try to wait for them to finish. # If needed, try to wait for them to finish.
# Call objects are not always awaitables. # Call objects are not always awaitables.

@ -120,6 +120,18 @@ class TestCloseChannel(AioTestBase):
for call in calls: for call in calls:
self.assertTrue(call.cancelled()) self.assertTrue(call.cancelled())
async def test_channel_isolation(self):
async with aio.insecure_channel(self._server_target) as channel1:
async with aio.insecure_channel(self._server_target) as channel2:
stub1 = test_pb2_grpc.TestServiceStub(channel1)
stub2 = test_pb2_grpc.TestServiceStub(channel2)
call1 = stub1.UnaryCall(messages_pb2.SimpleRequest())
call2 = stub2.UnaryCall(messages_pb2.SimpleRequest())
self.assertFalse(call1.cancelled())
self.assertTrue(call2.cancelled())
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)

Loading…
Cancel
Save