Server detecting client cancellation: C++ interface

938 views
Skip to first unread message

blake...@gmail.com

unread,
Jul 20, 2015, 10:41:47 AM7/20/15
to grp...@googlegroups.com
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:

  1. 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.
  2. 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 

Craig Tiller

unread,
Jul 20, 2015, 10:54:09 AM7/20/15
to blake...@gmail.com, grp...@googlegroups.com
Hey,

I thought I noticed a bug with IsCancelled as I was reading through some code on the weekend.
I guess you just confirmed it. Filed https://github.com/grpc/grpc/issues/2534 to track the fix.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/4730637f-398e-4ad6-9d9d-d5f199d07f95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blake Smith

unread,
Jul 20, 2015, 12:40:48 PM7/20/15
to Craig Tiller, grp...@googlegroups.com
Thanks Craig!

So the assumption is that ServerContext.IsCancelled() is supposed to return true upon a client cancellation?

Anything I can do to help with the issue you filed? (Code, testing, etc.)

Blake

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/-q9CyfltSB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Blake Smith
http://blakesmith.me
@blakesmith
Reply all
Reply to author
Forward
Message has been deleted
0 new messages