Hi Lidi,
Thanks for getting back. My application is for a long-lived bidirectional stream.
On the server, I need to detect a client disconnected. I understand multiple streams are multiplexed on same connection. However, in my case it is a long-lived bidirectional stream and the stream will terminate only when the client has died.
When stream is terminated, and if the client/stream does not reconnect to server within a timeout, the server will need to purge out state associated with the client.
I'm counting on "add_done_callback" being able to register a callback that gets invoked before the stream is terminated. This allows me to start the timer on server side to wait before purging state associated with the client/stream.
I was also suggested to look into enabling TCP keepalives - but I have not seen a way for the application to be notified if/when TCP connection is terminated.
If you have better ideas, I much appreciate it.
BTW, I quickly sifted through the PR, there is a suggestion to catch asyncio.CancelledError.. However, 1) I am not sure if asyncio.CancelledError is raised if client disconnects, and 2) whether application/server will have a chance to do anything about it before underlying aio thread get cleaned up?
async def handler(request, service_context):
try:
make_something(...)
except asyncio.CancelledError:
clean_stuff_related_to_current_RPC(....)
Regards,
Tarek