Correct way to Stop grpc Async server : C++

1,795 views
Skip to first unread message

Chaitanya Gangwar

unread,
Aug 8, 2016, 5:09:32 AM8/8/16
to grpc.io
Hi All,

My server implementation is, Async Streaming server.

What is the correct way to stop grpc Async server. As soon as i call this:

server_->Shutdown();
 cq_->Shutdown();

my handleRpc code (which is blocked on cq->Next ()), i am hitting Assert, as value of "ok" is false.

bool ret = cq_->Next(&tag, &ok);
GPR_ASSERT(ok);
 
I tried to check the return value for (cq->Next() ) , which is coming as true, but when i checked in manual, it says, Next returns false if server is shutting down. i can skip the assert if ret value is false, but in my case it is coming as true. Does Server expects all calldata instances to be deleted before closing the server as in my case, i am not deleting all calldata instances and directly shutting down the server

Please help me, what i am missing here.

Thanks
Chaitanya

Koen De Keyser

unread,
Aug 8, 2016, 5:24:02 PM8/8/16
to grpc.io
Your server has one or more RPC's, and doing a shutdown implies a Cancel on each RPC. This cancel results in all of the outstanding tags to become available (i.e. Next returns with the "tag" set) on the completion queue, but with the "ok" variable set to false. This indicates that this tag can no longer be returned by subsequent Next calls, and the operation associated with this tag was cancelled. This is the ideal moment to release resources associated with this tag.

Only after all of the tags that were still in use, have been returned by the Next calls, Next will start to return false. In that case, neither "tag" nor "ok" are set by grpc.

So there is a clear distinction between the purpose of "ok" and the bool that gets returned by Next.

Koen

Chaitanya Gangwar

unread,
Aug 9, 2016, 1:54:09 AM8/9/16
to grpc.io
Thanks Koen,  I also realized the same behavior after i did more testing. Thanks for help. Its working now.

-Chaitanya
Reply all
Reply to author
Forward
0 new messages