Thanks for the reply. I updated my test server method to the following 
(hopefully I understood correctly), although I observed no differences in 
behavior on the client-side:

public void testStream(TestRequest request, StreamObserver<TestResponse> 
responseObserver) {
  Context originalContext = Context.current();
  CancellableContext cancellableContext = originalContext.withCancellation();
  cancellableContext.attach();
  cancellableContext.detachAndCancel(originalContext, new 
RuntimeException("Server context canceled"));
}


It's the ClientResponseObserver that I'm inspecting to observe the 
cancellation, I suppose maybe expecting `onError` to get called on behalf 
of the server cancellation.

On Thursday, February 21, 2019 at 1:50:23 PM UTC-5, Carl Mastrangelo wrote:
>
> 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/4b15d98c-9253-4441-ba05-e4f55f6214f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to