I think you need to call `attach()` on the context to install it (rather than just construct it). Normally this sticks it in a thread local which gRPC then reads from.
On Wednesday, February 20, 2019 at 2:08:03 PM UTC-8, [email protected] wrote: > > > In the context of server streaming or bi-directional streaming calls, I'm > under the impression the client should be able to receive notice when the > server has decided to cancel the context for the call. I've been trying to > write up a test to capture this behavior, but it doesn't seem like > canceling the context on the server is triggering anything in the response > observer in the client side. Maybe I'm misinterpreting how the client > interacts with a server cancellation or just setting up the test case wrong? > > My client test call is something like: > > ClientResponseObserver<Object, TestResponse> closingObserver = > ClosingStreamObserver.closingClientResponseObserver(clientTestCloseable, > responseObserver); > serviceStub.testStream(req, closingObserver); > > > and then I wait a bit to see if anything propagates (I've got an atomic > boolean that I flip when `onError` or `onCompleted` get called. I had also > tried a listener on the current context on the client side as well, but that > seemed irrelevant. > > > On the server side I'm canceling the context something like this: > > public void testStream(TestRequest request, StreamObserver<TestResponse> > responseObserver) { > CancellableContext cancellableContext = > Context.current().withCancellation(); > cancellableContext.cancel(new RuntimeException("Server context canceled")); > } > > > To step back a bit, I'm looking to know if and how a server can signal it is > canceling a request to the client. > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/b510d79c-a9e5-43e6-b677-eb55119f7641%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
