Consider an rpc service which continuously streams a response from server to client:
rpc stream_stuff(MyStreamRequest) returns (stream MyStreamResponse);
The Request contains data which specifies how much data to send and how often, including an option to stream for an unspecified amount of time.
The ClientContext
object provides a TryCancel()
method which allows for a best effort attempt to cancel the rpc. This works to first order. However the docs are emphatic that this might not always work.
Is TryCancel()
the standard way this is handled or should I build cancellation into the service somehow (e.g. via multidirectional stream which the server checks for cancellation)?
If neither, what is the best way to handle this situation?
There is a response in the official gRPC repo by one of the developers that TryCancel()
is "the right way to cancel a stream".