Stream is closed for idle connection

952 views
Skip to first unread message

Roshan Chaudhari

unread,
Jan 13, 2022, 1:18:55 AM1/13/22
to grpc.io
I have bidirectional streaming rpc between server and client. If data is not exchanged over the stream, after certain time, on the server, it seems that stream is disconnected or stream-Read() returns false.

Currently I am not using keepalive flags for the channel on server and client.
There is a flag:
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS
: This channel argument if set to 1 (0 : false; 1 : true), allows keepalive pings to be sent even if there are no calls in flight.
what is meaning of "no calls in flight" ?

Is this the option will help me out to solve my issue?


-
Roshan

Mark D. Roth

unread,
Jan 19, 2022, 5:19:09 PM1/19/22
to grpc.io
There are a number of reasons why the stream might be closed.  The server might close the individual stream, or the underlying connection as a whole might be dropped, which will implicitly close all streams active at the moment when the connection is dropped.  When stream->Read() returns false, you should call stream->Finish() to get the RPC's status, and the status message should tell you why the stream failed.

If the problem is that the stream failed because the underlying connection was closed because of idleness, then keepalive might be a good way to address that.  The keepalive knobs are documented at https://github.com/grpc/grpc/blob/master/doc/keepalive.md.  GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS is probably not the knob you want, because in this case, you do have an active call (note: "call" and "stream" are the same thing in this context).  I think you would just need to set GRPC_ARG_KEEPALIVE_TIME_MS.

I hope this info is helpful.

Roshan Chaudhari

unread,
Jan 20, 2022, 5:11:13 AM1/20/22
to grpc.io
Thanks Mark for responding.!

On client side, I did not receive a notification that server/stream closed. On server, after Read()->false, context_->IsCancelled() is true. Also, I have seen this client running on windows and server on linux. When I checked client as well on Linux, it did not reproduce.

There is a default value for GRPC_ARG_KEEPALIVE_TIME_MS = 2 hours. So that means if my bidi stream/session is not explicitly terminated by any parties and assuming connection is active, server should not be closed by any reason.
Reply all
Reply to author
Forward
0 new messages