what to do when ServerCompletionQueue::Next return false?

484 views
Skip to first unread message

zhang...@gmail.com

unread,
Jan 16, 2017, 3:47:16 AM1/16/17
to grpc.io
CallData* cd = NULL;
bool ok = false;
while( cq->Next(reinterpret_cast<void**>(&cd), &ok) ) {
if( ok ) {
cd->Proceed();
} else {
// what to do here?
 }
}

In my grpc server, I found the 2nd parameter of ServerCompletionQueue::Next sometimes returns false.

If I do nothing in this case, CallData exhaust after a while and the program hang at the 3rd line (the start of the while loop).

but from the examples, I didn't find a correct way to handle this.

Is there an example for this, thanks.

Vijay Pai

unread,
Jan 23, 2017, 2:16:38 PM1/23/17
to zhang...@gmail.com, grpc.io
Hello there,
Thanks for the detailed question and feedback! The ok parameter indicates whether or not the operation completed "normally". When it is false, it means that no more operations on that side of the RPC (Read-side or Write-side) will ever return true in the future (e.g., a server Read will never return true again after the client has done a WritesDone). In some cases, it might mean that operations on both sides of the RPC will never return true in the future (e.g., if the RPC was cancelled or had its deadline exceeded). The way to handle it will typically be to mark some information in your class to indicate that type of progress has occurred. That said, the only conclusive way of knowing the RPC status is with a call to Finish. The ok parameter just tells you explicitly about one side of the RPC.

- Vijay

--
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.
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/87b2b09a-c825-4ea6-ae3a-ffcecec5b1eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sree Kuchibhotla

unread,
Jan 23, 2017, 4:52:22 PM1/23/17
to Vijay Pai, zhang...@gmail.com, grpc.io
In addition to what Vijay Said, I wanted to address the following you mentioned:

  >>  If I do nothing in this case, CallData exhaust after a while and the program hang at the 3rd line (the start of the while loop).

By the way, I am assuming you are using the grpc async server example from here.  If ok==false, you still need to do  'service_->RequestMethodName() to let grpc know that it should accept a new method like here for example. Otherwise, the server will not be able to accept any new incoming method that it doesn't know about - and this is the reason why cq->next() doesn't return

 (NOTE: If ok == true, things are working well because  I am sure your code is also doing soemthing similar to what is done in the example. i.e   cd->proceed() is called with status_ == PROCESS and the first thing it does is to create a new CallData object whose constructor calls Proceed() - which ends up calling service_->RequestSayHello())

thanks,
Sree




On Mon, Jan 23, 2017 at 11:16 AM, 'Vijay Pai' via grpc.io <grp...@googlegroups.com> wrote:
Hello there,
Thanks for the detailed question and feedback! The ok parameter indicates whether or not the operation completed "normally". When it is false, it means that no more operations on that side of the RPC (Read-side or Write-side) will ever return true in the future (e.g., a server Read will never return true again after the client has done a WritesDone). In some cases, it might mean that operations on both sides of the RPC will never return true in the future (e.g., if the RPC was cancelled or had its deadline exceeded). The way to handle it will typically be to mark some information in your class to indicate that type of progress has occurred. That said, the only conclusive way of knowing the RPC status is with a call to Finish. The ok parameter just tells you explicitly about one side of the RPC.

- Vijay
On Mon, Jan 16, 2017 at 12:47 AM <zhang...@gmail.com> wrote:
CallData* cd = NULL;
bool ok = false;
while( cq->Next(reinterpret_cast<void**>(&cd), &ok) ) {
if( ok ) {
cd->Proceed();
} else {
// what to do here?
 }
}

In my grpc server, I found the 2nd parameter of ServerCompletionQueue::Next sometimes returns false.

If I do nothing in this case, CallData exhaust after a while and the program hang at the 3rd line (the start of the while loop).

but from the examples, I didn't find a correct way to handle this.

Is there an example for this, thanks.

--
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+unsubscribe@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/87b2b09a-c825-4ea6-ae3a-ffcecec5b1eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
Reply all
Reply to author
Forward
0 new messages