grpc c++ stream blocked when connect to an unavailable server

1,152 views
Skip to first unread message

yangya...@gmail.com

unread,
May 23, 2016, 10:34:47 PM5/23/16
to grpc.io
I have a server-side stream client, when server is unavailabe, client is blocked in ClientReader::Read. How can I known the server is UNAVAILABLE and canncel the Read, or is there a way to know UNAVAILABLE status before Read?

Craig Tiller

unread,
May 24, 2016, 7:19:06 AM5/24/16
to yangya...@gmail.com, grpc.io

Which version of gRPC are you using?

For prior to 0.14, the best available advice was to set a deadline on the stream (so it times out), and if you needed more watch the connectivity state of the channel.

With 0.14 we introduced and defaulted all streams to fail fast semantics, so if the underlying channel fails to connect you'll get an unavailable status when we detect that.


On Mon, May 23, 2016, 10:34 PM <yangya...@gmail.com> wrote:
I have a  server-side stream client, when server is unavailabe, client is blocked in ClientReader::Read. How can I known the server is UNAVAILABLE and canncel the Read, or is there a way to know UNAVAILABLE status before Read?

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/69c4ae5f-e805-4e3b-9f9a-a5bd2483a134%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yangya...@gmail.com

unread,
May 25, 2016, 11:29:57 AM5/25/16
to grpc.io
Hi, my version has fail_fast, and I checked the state of channel. When server is shutdown, the state is GRPC_CHANNEL_CONNECTING, which helps me know server is unavailable.
Thank you!

csen...@gmail.com

unread,
Dec 4, 2017, 3:22:34 PM12/4/17
to grpc.io
Hi,
Can you help me understand how did you overcome this issue.  I too have a client that invokes streaming rpc and it gets blocked in ClientReader::Read.
I cant set a timeout as it would mean the rpc needs to be invoked again after the timeout.

I need a way to reestablish the server connection if client gets blocked in ClientReader::Read.  I cannot read the connection state as the call is blocked.
However Read fails and gets unblocked if
- I kill the server process or unplug the connection between client and server
But the client gets blocked indefinitely when the server is shutdown/powered off.

My code goes like this....
ClientContext context;
std::unique_ptr<Consumer::Stub> stub_ = Consumer::NewStub(channel);
ThreadEventReader = stub_->GetDataStream(&context, Filter);  //rpc call
// blocked read - until stream closed
while (ThreadEventReader->Read(&StreamedData))
{
                cout << "UpdateStream: " << StreamedData.displayvalue() << endl;
}

Yang Gao

unread,
Dec 7, 2017, 5:26:45 PM12/7/17
to grpc.io
You can set a deadline to your stream. Re-issuing the rpc is not really a problem because a failed read at the client means the rpc is done at the server or failed somehow anyway.

Or you can configure client side channel keep alive by adding channel arguments: GRPC_ARG_KEEPALIVE_TIME_MS and GRPC_ARG_KEEPALIVE_TIMEOUT_MS. See https://github.com/grpc/grpc/blob/a8021572683c4a6e6af59888cf3a000933abe00c/include/grpc/impl/codegen/grpc_types.h#L218

csen...@gmail.com

unread,
Dec 7, 2017, 10:37:35 PM12/7/17
to grpc.io
Thanks for your reply.

I have considered those options and it would not work for me.
1. The streaming rpc will provide incremental on change data from server to the client, if I set the deadline the streaming rpc gets reestablished if server is still connected and have no data to send within the period configured in the deadline.  I do not want the client to reconnect and get the stale data when the server has not really broken and keeps idle.
2. I am still using grpc v1.0.0 and keep alive channel arguments are not supported in that version.  I may need to upgrade to v1.6.0.

Just wondering if there are any other options with v1.0.0.  
Thanks again for your reply,
Reply all
Reply to author
Forward
0 new messages