Skip to content

[Aio] Gracefully handle RPCs ends pre-maturely#25884

Merged
lidizheng merged 2 commits intogrpc:masterfrom
lidizheng:fix-empty-headers
Apr 5, 2021
Merged

[Aio] Gracefully handle RPCs ends pre-maturely#25884
lidizheng merged 2 commits intogrpc:masterfrom
lidizheng:fix-empty-headers

Conversation

@lidizheng
Copy link
Copy Markdown
Contributor

@lidizheng lidizheng commented Apr 5, 2021

In cases like cancellation/broken gRPC traffic, the RPC might end very quickly that the user provided initial metadata haven't been set yet. That triggers a bug in existing code to generate an error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/var/local/git/grpc/src/python/grpcio_tests/tests_aio/unit/_test_base.py", line 31, in wrapper
    return loop.run_until_complete(f(*args, **kwargs))
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "/var/local/git/grpc/src/python/grpcio_tests/tests_aio/interop/local_interop_test.py", line 73, in test_empty_stream
    self._stub, None)
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
    return self.gen.throw(type, value, traceback)
  File "/var/local/git/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py", line 449, in test_interoperability
    await method(stub)
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
    return self.gen.throw(type, value, traceback)
  File "/var/local/git/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py", line 247, in _empty_stream
    assert await call.read() == aio.EOF
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
    return self.gen.throw(type, value, traceback)
  File "/var/local/git/grpc/py36_asyncio/lib/python3.6/site-packages/grpc/aio/_call.py", line 353, in read
    response_message = await self._read()
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
    return self.gen.throw(type, value, traceback)
  File "/var/local/git/grpc/py36_asyncio/lib/python3.6/site-packages/grpc/aio/_call.py", line 331, in _read
    await self._preparation
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 126, in send
    return self.gen.send(value)
  File "/var/local/git/grpc/py36_asyncio/lib/python3.6/site-packages/grpc/aio/_call.py", line 624, in _prepare_rpc
    self._metadata, self._metadata_sent_observer)
  File "src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi", line 499, in initiate_stream_stream
  File "src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi", line 164, in grpc._cython.cygrpc._AioCall._set_initial_metadata
TypeError: 'NoneType' object is not iterable

Fixes #25873


This change is Reviewable

@lidizheng lidizheng added lang/Python release notes: no Indicates if PR should not be in release notes labels Apr 5, 2021
@lidizheng lidizheng marked this pull request as ready for review April 5, 2021 23:38
@lidizheng lidizheng requested a review from gnossen April 5, 2021 23:39
Copy link
Copy Markdown
Contributor

@gnossen gnossen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool that the local_interop test caught this issue.

@lidizheng lidizheng enabled auto-merge (squash) April 5, 2021 23:55
@lidizheng lidizheng merged commit 09f17db into grpc:master Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/Python release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flake: python_linux_opt_asyncio_py36_asyncio_test_aio_interop_local_interop_test_SecureLocalInteropTest

2 participants