You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a call is canceled, the upstream sends RST_FRAME. We can make the same effect by calling RequestContext.cancel().
It sounds easy but the implementation on the client side could be tricky. On the call path, ClientInterceptor is called first, and then ArmeriaChannel is called.
As ClientRequestContext is created in ArmeriaChannel, ClientRequestContext is inaccessible in ClientInterceptor. So our aim to call 'RequestContext.cancel()' is not feasible.
The idea I came up with is to add a ClientInterceptor in the GrpcClientBuilder that gets executed first. The interceptor registers a CancellationListener to CancellationContext. The reference of the registered CancellationListener should be also added to CallOptions so that we can update ClientRequestContext to the reference in ArmeriaChannel.newCall().
staticCallOptions.Key<CancellationHandler> KEY = CallOptions.Key.create(CancellationHandler.class.getName());
classCancellableClientInterceptor {
...
@Overridepublic <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptionscallOptions,
Channelnext) {
// CancellationHandler will defer the cancellation until `ClientRequestContext` to this.finalCancellationHandlerhandler = newCancellationHandler();
// KEY will be used in ArmeriaChannel.newCall() to get `handler`callOptions = callOptions.withOption(KEY, handler);
finalCancellableContextcontext = Context.current().withCancellation();
context.addListener(handler, MoreExecutors.directExecutor());
Contextprevious = context.attach();
try {
returnnext.newCall(method, callOptions);
} finally {
context.detach(previous);
}
}
}
The text was updated successfully, but these errors were encountered:
I understand that this issue requirement is To call RequestContext.cancel() when gRPC level cancellation occurs.
Thank you for sharing your idea and implementation outline.
I'm not completely sure the following implementation and how this handler can access to ClientRequestContext.
// CancellationHandler will defer the cancellation until `ClientRequestContext` to this.finalCancellationHandlerhandler = newCancellationHandler();
Do you have your idea about this already?
If so, it would be helpful if you could share.
Currently, Armeria gRPC implementation does not support cancellation at the gRPC level.
https://github.com/grpc/grpc-java/blob/1d6f1f1b4251191bddb9d6605fc8f8152275b6b7/examples/src/main/java/io/grpc/examples/cancellation/CancellationClient.java#L57
When a call is canceled, the upstream sends RST_FRAME. We can make the same effect by calling
RequestContext.cancel()
.It sounds easy but the implementation on the client side could be tricky. On the call path,
ClientInterceptor
is called first, and thenArmeriaChannel
is called.As
ClientRequestContext
is created inArmeriaChannel
,ClientRequestContext
is inaccessible inClientInterceptor
. So our aim to call 'RequestContext.cancel()' is not feasible.The idea I came up with is to add a
ClientInterceptor
in theGrpcClientBuilder
that gets executed first. The interceptor registers aCancellationListener
toCancellationContext
. The reference of the registeredCancellationListener
should be also added toCallOptions
so that we can updateClientRequestContext
to the reference inArmeriaChannel.newCall()
.The text was updated successfully, but these errors were encountered: