If a Channel is in GRPC_CHANNEL_SHUTDOWN state, how should I delete all stubs and ClientAsyncReaderWriters?

22 views
Skip to first unread message

topin89

unread,
Aug 30, 2024, 1:09:01 PMAug 30
to grpc.io
Let's suppose there's async bidirectional stream in progress. So, a Channel is created, then it produces a Stub that used with a ClientAsyncReaderWriter to put Read and Write event in completion queue.

Now, for some reason, Channel is failed so hard it is in GRPC_CHANNEL_SHUTDOWN state. And I need to recreate a channel, a stub and reconnect it and then place tags again. And there are some tags in the completion queue. I'm not sure what's safe to assume at this point.

Can I assume that the moment a channel is shutdown, all tags are immediately in the queue with "not ok" flag and if there's a finish tag, a status used with the  ClientAsyncReaderWriter is guaranteed to be set to something, so I can safely delete the failed channel and all stubs with responders in no particular order, or there should be some deinitialization sequence like:
  • Wait for all tags placed by a particular ReaderWriter are out of the queue
  • Then delete the ReaderWriter
  • When all ReaderWriters are deleted, then delete all stubs
  • When all stubs are deleted, then I can delete the Channel that created the stubs
  • After that, I should recreate a Channel and all the things to restart all streams
Or maybe something in between.

Couldn't find that in the docs (if there is, link please) and ChatGPT is definitely not a reliable source, so here's the question.

Also, maybe there's no way for Channel to be in GRPC_CHANNEL_SHUTDOWN at all unless there's memory corruption, so it's better to restart the whole app, or it can happen if a mobile network is out of range and for some reason even DNS servers are unavailable.
Reply all
Reply to author
Forward
0 new messages