Client code blocks on StreamUnary call if server crashes
sanlem opened this issue · comments
What version of gRPC and what language are you using?
Python
grpcio==1.46.0
What operating system (Linux, Windows,...) and version?
MacOS 12.3
What runtime / compiler are you using (e.g. python version or version of gcc)
Python 3.8.13
What did you do?
`async with grpcaio.insecure_channel(server_location) as channel:
stub = pb2_grpc.TradingServiceStub(channel)
service_events_task = asyncio.create_task(self._process_service_events(stub))
trading_events_task = asyncio.create_task(self._process_trading_events(stub))
self._trading_stream = stub.Trading(requests_stream)
print(111111111)
await self._trading_stream
print(2222222)
`
Trading is stream-unary rpc. Everything was working great before my server crashed and entire application that uses the code above was blocked. _process_service_events and _process_trading_events simply initialise and read
unary-stream rpcs. When I run this, then stop the server - I see exception inside _process_service_events: <class 'grpc.aio._call.AioRpcError'> <AioRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Socket closed"
debug_error_string = "{"created":"@1654693453.665480000","description":"Error received from peer ipv6:[::1]:53051","file":"src/core/lib/surface/call.cc","file_line":953,"grpc_message":"Socket closed","grpc_status":14}"
But await self._trading_stream seems causing a deadlock, because 2222222 never gets printed.
What did you expect to see?
I expect exception from await self._trading_stream or await to get completed and my code unblocked.
What did you see instead?
I see that await self._trading_stream newer finishes and blocks whole app.
Thank you for the report. Is there any chance you can provide a repro case that I can easily use?
So I created a blank test project, and this issue doesn't reproduce.
Original issue occurred both on my development MacOS machine and on linux server.
Still don't know what's wrong, but I refactored my original code that caused the issue to single bidi stream api and it works that way.
Closing since not reproducible, please open a new issue if this still happens.