I'm experimenting gRPC in c++ and I'm not sure what I want to achieve is possible with the framework.
- a single connection btw the client and the server
- the client to be able to send multiple requests to the server from different threads (sync or async is fine)
- 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