Skip to content

Commit

Permalink
SmallRye Health: terminate request context properly
Browse files Browse the repository at this point in the history
When the SmallRye Health route handler activates request context on its own,
it also needs to terminate it. However, that termination needs to happen
only after all health checks complete. That's what this commit does.
  • Loading branch information
Ladicek committed Feb 20, 2024
1 parent 5044d93 commit be801fe
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ abstract class SmallRyeHealthHandlerBase implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
ManagedContext requestContext = Arc.container().requestContext();
if (requestContext.isActive()) {
doHandle(ctx);
doHandle(ctx, null);
} else {
requestContext.activate();
try {
doHandle(ctx);
} finally {
doHandle(ctx, requestContext);
} catch (Exception e) {
requestContext.terminate();
throw e;
}
}
}

private void doHandle(RoutingContext ctx) {
private void doHandle(RoutingContext ctx, ManagedContext requestContext) {
QuarkusHttpUser user = (QuarkusHttpUser) ctx.user();
if (user != null) {
Arc.container().instance(CurrentIdentityAssociation.class).get().setIdentity(user.getSecurityIdentity());
Expand All @@ -48,6 +49,9 @@ private void doHandle(RoutingContext ctx) {
Context context = Vertx.currentContext();
getHealth(reporter, ctx).emitOn(MutinyHelper.executor(context))
.subscribe().with(health -> {
if (requestContext != null) {
requestContext.terminate();
}
HttpServerResponse resp = ctx.response();
if (health.isDown()) {
resp.setStatusCode(503);
Expand Down

0 comments on commit be801fe

Please sign in to comment.