Hey GRPC!
I have an rpc IDL definition that looks like this:
service Ledgerd {
rpc StreamPartition(StreamPartitionRequest) returns (stream LedgerdMessageSet) {}
}
The assumption is that the client will hold the stream open until it's done consuming messages (could be 'indefinitely'). A few questions arise out of this scenario:
- Using the C++ interface, how can my server code detect when a client cancellation has happened? I tried putting a sleeping while loop around ServerContext#IsCancelled, but it doesn't appear that IsCancelled ever returns true for a client cancellation.
- Do client cancellations send any bidirectional communication to the server to notify of the cancellation?
My client test code looks something like this (client cancels the stream after reading the first message):
grpc::ClientContext rcontext;
std::unique_ptr<grpc::ClientReader<LedgerdMessageSet>> reader(client->StreamPartition(&rcontext, sreq));
ASSERT_EQ(true, reader->Read(&messages));
rcontext.TryCancel();
grpc::Status sstatus = reader->Finish();
ASSERT_EQ(grpc::StatusCode::CANCELLED, sstatus.error_code());
Server code snipped looks something like this:
auto producer = doWorkInAnotherThread(writer);
while(!context.IsCancelled()) {
sleep(1);
}
producer.Stop();
producer.Wait();
Again, the problem is IsCancelled never returns true, so I'm not sure how the server can be notified that the client has cancelled and clean up my server side producer. I found these two other list discussions, but one seems about the Java interface, and the other seems to be getting cancellation on the client side:
Any ideas? Loving GRPC so far - thanks!
Blake