Properly shutdown gRPC CompletionQueue (client side)

2,314 views
Skip to first unread message

ernest.w....@gmail.com

unread,
Jul 30, 2018, 1:26:39 AM7/30/18
to grpc.io
I have multiple ClientAsyncReaderWriters using the same CompletionQueue. How properly shutdown it once I want to destroy instance of my class? Is it enough to call WritesDone on each stream and then break the CompletionQueue loop? Should I call Shutdown on CQ? I have found a lot of server side examples where the Shutdown is called on CQ but never saw it in client code. Its quite puzzling.

Sree Kuchibhotla

unread,
Jul 30, 2018, 12:31:58 PM7/30/18
to ernest.w....@gmail.com, grpc.io
The proper way to shutdown would be to call WritesDone on each stream, call Completion queue shutdown, then keep calling CompletionQueue.Next() until it returns 'false'.   At this point, it is ok to destroy the completion queue.

thanks,
-Sree

On Sun, Jul 29, 2018 at 10:26 PM <ernest.w....@gmail.com> wrote:
I have multiple ClientAsyncReaderWriters using the same CompletionQueue. How properly shutdown it once I want to destroy instance of my class? Is it enough to call WritesDone on each stream and then break the CompletionQueue loop? Should I call Shutdown on CQ? I have found a lot of server side examples where the Shutdown is called on CQ but never saw it in client code. Its quite puzzling.

--
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/b59dade1-289e-4fb6-8578-13fcc65e0e1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

E.W.Z.

unread,
Jul 30, 2018, 12:44:46 PM7/30/18
to Sree Kuchibhotla, grpc.io

This is what I’ve seen (and done in my code) on the net (particularly in this group), however the Next never returns. Interestingly, I didn’t find any example shutting down CQ this way, just to see it working. Any idea how to analyze why it would happen? Any type of logging or something that can shed some light why Next never returns?

 

BTW, in what context I can call Shutdown method? Can I call it in main thread to stop the `Next`ing loop which runs in another thread?

 

 

Sent from Mail for Windows 10

Sree Kuchibhotla

unread,
Jul 30, 2018, 1:02:08 PM7/30/18
to ernest.w....@gmail.com, grpc.io
Next() not returning would mean that your completion queue still has some pending tags that are expected.  Are you sure all the operations that you started on the completion queue are completed?

Secondly, calling Shutdown() is not strictly needed because completion queue's destructor will call shutdown anyway. However, explicitly calling Shutdown makes the code cleaner. You can call Shutdown() from any thread - it need not be from the thread doing `Next` 

Try turning on "api" and "op_failure" traces (more description here) to debug this. (i.e set envoronment variable GRPC_TRACE=api,op_failure  and GRPC_VERBOSITY=DEBUG)

thanks,
Sree

ernest.w....@gmail.com

unread,
Jul 30, 2018, 1:16:10 PM7/30/18
to grpc.io
Thats it, I'm counting operations and dont see how anything could be pending in the queue. If I break the loop on destruction and destroy objects I get following cryptic message
E0730 10:29:23.205691020   20545 backup_poller.cc:110]       run_poller: {"created":"@1532935763.205628727","description":"Shutting down timer system","file":"src/core/lib/iomgr/timer_generic.cc","file_line":704}

Will try tracing the stuff tomorrow. Thank you for the input.

seazo...@gmail.com

unread,
Mar 22, 2019, 8:58:35 AM3/22/19
to grpc.io
Hi,ernest
have solved this problem? i got the same message.

在 2018年7月31日星期二 UTC+8上午1:16:10,ernest.w....@gmail.com写道:

ernest.w....@gmail.com

unread,
Mar 22, 2019, 10:56:01 AM3/22/19
to grpc.io
As far as I remember, we elegantly dismissing the message, and everything looks like working. Just make sure you really finish all outstanding stuff in the queue

seazo...@gmail.com

unread,
Mar 23, 2019, 10:06:37 PM3/23/19
to grpc.io

Okay, Thank you very much.

在 2019年3月22日星期五 UTC+8下午10:56:01,ernest.w....@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages