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.

(cherry picked from commit 650ec93)
  • Loading branch information
Ladicek authored and gsmet committed Feb 20, 2024
1 parent d4e9086 commit 4d54338
Showing 1 changed file with 12 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 All @@ -60,6 +64,10 @@ private void doHandle(RoutingContext ctx) {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}, failure -> {
if (requestContext != null) {
requestContext.terminate();
}
});
}
}

0 comments on commit 4d54338

Please sign in to comment.