Skip to content

Commit

Permalink
Merge pull request #38888 from Ladicek/health-request-context-termina…
Browse files Browse the repository at this point in the history
…tion

SmallRye Health: terminate request context properly
  • Loading branch information
gsmet authored Feb 20, 2024
2 parents f4aece6 + 650ec93 commit f4c0c9a
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 f4c0c9a

Please sign in to comment.