(golang) Stream cancellation behavior?

1,280 views
Skip to first unread message

Scott Devoid

unread,
Jun 6, 2016, 5:59:23 PM6/6/16
to grp...@googlegroups.com
Hi,

I have a few questions about how gRPC cancellation works in Golang:

First, what are the conditions under which a request could be
cancelled? I can think of a two but let me know if I am missing some
or incorrect:

- client cancels context.Context passed into request.
- TCP socket closes after a timeout?
- HTTP/2 client/server sends RST_STREAM for...reasons?

Second, if the client cancels the context, is the server notified
about this (assuming no loss of connectivity)? Can I select on
req.Context().Done() and perform some clean-up work after the fact or
does the request handler immediately return?

Third, in one of our bidirectional gRPC methods[1] we see a 'stream
error: code = 1 desc = "context cancelled"' event. However the client
passed in a context.Background() to the request so as far as I can
tell this cancellation has to be happening in grpc internals some
place. Does anyone know what is going on here?

Thanks!

~ Scott Devoid

[1] rpc Foo(stream Req) returns (stream Resp) {}

Scott Devoid

unread,
Jun 13, 2016, 12:15:22 PM6/13/16
to grp...@googlegroups.com
Any advice here would be appreciated.

Thanks,
~ Scott Devoid

Qi Zhao

unread,
Jun 13, 2016, 2:11:06 PM6/13/16
to Scott Devoid, grpc-io
On Mon, Jun 6, 2016 at 2:59 PM, Scott Devoid <sde...@gmail.com> wrote:
Hi,

I have a few questions about how gRPC cancellation works in Golang:

First, what are the conditions under which a request could be
cancelled? I can think of a two but let me know if I am missing some
or incorrect:

- client cancels context.Context passed into request.
- TCP socket closes after a timeout?
- HTTP/2 client/server sends RST_STREAM for...reasons?

The 1st and 3rd are the reasons. the 2nd won't cause a cancellation error. 
Second, if the client cancels the context, is the server notified
about this (assuming no loss of connectivity)? Can I select on
req.Context().Done() and perform some clean-up work after the fact or
does the request handler immediately return?
Yes, cancellation will propagate to the server if it is needed.  

Third, in one of our bidirectional gRPC methods[1] we see a 'stream
error: code = 1 desc = "context cancelled"' event. However the client
passed in a context.Background() to the request so as far as I can
tell this cancellation has to be happening in grpc internals some
place. Does anyone know what is going on here?
Not sure, perhaps the server initiated the cancellation. 

Thanks!

~ Scott Devoid

[1] rpc Foo(stream Req) returns (stream Resp) {}

--
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+unsubscribe@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/CAJrQjSvM3BZv9kBYJCdVCNGxxqzsSDCWGWKe%3DeoY43tUQ%3DV78g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks,
-Qi
Reply all
Reply to author
Forward
0 new messages