[c++] Concurrent RPC calls

264 views
Skip to first unread message

Christophe Calmejane

unread,
Sep 16, 2022, 9:44:17 AM9/16/22
to grpc.io
Hi,

I'm experimenting gRPC in c++ and I'm not sure what I want to achieve is possible with the framework.

I need:
  1. a single connection btw the client and the server
  2. the client to be able to send multiple requests to the server from different threads (sync or async is fine)
  3. the server to be able to send messages to the client at any time (observer pattern)
So what I implemented is the following:

I declared a "registerObserver" RPC in my proto file, as well as some unary commands.

On the server side (not in callback mode), when I receive the registerObserver command, I store the grpc::ServerWriter and don't return from the method until cancelled by the client. Whenever another server thread needs to send a message to the client, it just uses the stored ServerWriter.
For the unary commands, I simply handle them inline and return the status immediately.

On the client side, I created a grpc::ClientReadReactor to handle the stream of messages from the server, and sync/async calls for the unary commands my client wants the server to handle.

So, it seems to be working nicely, except when the server writes 2 messages at the same time. Whether an actual write call using my stored ServerWriter, or an indirect write when I return a status in a unary handler.
In such a case, the client always crashes in RunInterceptor.

So my questions are:
  • is it even possible to have the server (and the client) handle multiple rpc from the same client in parallel, including a streaming call?
  • if yes, how to properly achieve this?

Thanks for your insight,
Chris

Christophe Calmejane

unread,
Sep 26, 2022, 4:14:56 AM9/26/22
to grpc.io
Hi,

is there something else I can add to clarify my issue?
Why would the client crash because of the server responding to 2 different calls at the same time (or maybe something else is going on)?

Thank you

yas...@google.com

unread,
Feb 5, 2025, 8:47:06 PMFeb 5
to grpc.io
Hey, checking in. I know this is very late, but better late than never I guess...
I do not see any problem and yes, that should work. Servers can handle multiple RPCs from the same client in parallel, including a streaming call. 
The client crash seems like a bug somewhere. If you can share code, we can help spot the bug. If instead it's a bug in gRPC, we will handle it at https://github.com/grpc/grpc/issues.

In the past year, we have also updated our docs on the APIs, please check them out as well.
Reply all
Reply to author
Forward
0 new messages