grpclib icon indicating copy to clipboard operation
grpclib copied to clipboard

Re-connect after getting StreamTerminatedError

Open ahmdrz opened this issue 1 year ago • 0 comments

Is there any way to reconnect after getting StreamTerminatedError?

max_retries = 5
for retries in range(max_retries):
    try:
        await stream.send_message(...)
        break
    except StreamTerminatedError as e:
        if (retries + 1) == max_retries:
            raise e
        # Reconnect here
        await asyncio.sleep(10)

I wanted to reconnect to the channel and try sending a message again without creating another context or whole stream connection. Are there any tricks? I just wanted to ensure about sending a specific message.

ahmdrz avatar Feb 07 '23 10:02 ahmdrz