Call ClientReader's Finish() function ahead of schedule will cause program block forever

852 views
Skip to first unread message

xiaona...@gmail.com

unread,
Sep 28, 2017, 2:13:18 AM9/28/17
to grpc.io
Hi all,

I am using "A server-side streaming RPC where the client sends a request to the server and gets a stream to read a sequence of messages back. " mode:  

rpc transaction(request) returns (stream response) {}

My current Client cod's logic is: if find response message format error, doesn't receive the rest message, call the ClientReader's Finish() function:

while (reader->Read(&response)) {
      if (response is error) {
break;
 }
}

reader->Finish();

The Server's code is simple, just for-loop write all responses:  

for (...) {
writer->Write(response); 

But I find if Client doesn't read all responses, the  "reader->Finish();" will block forever. So my current solution is even the response has error, Client still need to 
read all responses.  

So my question is what is the correct method to only process half of the stream response? Must read all responses? 

Thanks very much in advance!

Best Reagrds
Nan Xiao

Carl Mastrangelo

unread,
Oct 3, 2017, 8:47:16 PM10/3/17
to grpc.io
What language are you using?

Nan Xiao

unread,
Oct 3, 2017, 10:59:50 PM10/3/17
to Carl Mastrangelo, grpc.io
Hi Carl,

C++, thanks!
Best Regards
Nan Xiao
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "grpc.io" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/grpc-io/R0NTqKaHLdE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> grpc-io+u...@googlegroups.com.
> To post to this group, send email to grp...@googlegroups.com.
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/76b84113-8de9-4475-a483-c20a1b83cb87%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Vijay Pai

unread,
Oct 5, 2017, 4:46:47 PM10/5/17
to grpc.io
The confusion comes from the name, I think. "Finish" is alerting the system that your code is ready to get the status and isn't going to do anything more to the stream, but it isn't forcibly shutting down the stream. If you want to forcibly shut down the stream, just call a TryCancel on the ClientContext object. 


On Wednesday, September 27, 2017 at 11:13:18 PM UTC-7, xiaona...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages