Skip to content

Commit

Permalink
gRPC fix request context clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
michalszynkiewicz committed Apr 27, 2021
1 parent 9653238 commit 0113ade
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.grpc.ServerInterceptor;
import io.grpc.Status;
import io.quarkus.arc.Arc;
import io.quarkus.arc.InjectableContext;
import io.quarkus.arc.ManagedContext;
import io.vertx.core.Context;
import io.vertx.core.Handler;
Expand All @@ -31,9 +32,13 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re
// This interceptor is called first, so, we should be on the event loop.
Context capturedVertxContext = Vertx.currentContext();
if (capturedVertxContext != null) {
InjectableContext.ContextState state;
boolean activateAndDeactivateContext = !reqContext.isActive();
if (activateAndDeactivateContext) {
reqContext.activate();
state = reqContext.getState();
} else {
state = null;
}
return next.startCall(new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
Expand All @@ -43,7 +48,7 @@ public void close(Status status, Metadata trailers) {
capturedVertxContext.runOnContext(new Handler<Void>() {
@Override
public void handle(Void ignored) {
reqContext.deactivate();
reqContext.destroy(state);
}
});
}
Expand Down

0 comments on commit 0113ade

Please sign in to comment.