diff --git a/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusRequestFilter.java b/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusRequestFilter.java index ac874f1ab2..e726176591 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusRequestFilter.java +++ b/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusRequestFilter.java @@ -53,11 +53,10 @@ public class QuarkusRequestFilter extends AbstractRequestFilter implements Handl // we need to close the session before response is sent to the client, otherwise subsequent requests could // not get the latest state because the session from the previous request is still being closed // other methods from Vert.x to add a handler to the response works asynchronously - context.addHeadersEndHandler(event -> close(session)); + context.addHeadersEndHandler(createEndHandler(context, promise, session)); context.next(); - promise.complete(); } catch (Throwable cause) { - promise.fail(cause); + context.fail(cause); // re-throw so that the any exception is handled from parent throw new RuntimeException(cause); } @@ -65,6 +64,18 @@ public class QuarkusRequestFilter extends AbstractRequestFilter implements Handl }, false, EMPTY_RESULT); } + private Handler createEndHandler(RoutingContext context, io.vertx.core.Promise promise, + KeycloakSession session) { + return event -> { + try { + close(session); + promise.complete(); + } catch (Throwable cause) { + context.fail(cause); + } + }; + } + private void configureContextualData(RoutingContext context, ClientConnection connection, KeycloakSession session) { // quarkus-resteasy changed and clears the context map before dispatching // need to push keycloak contextual objects into the routing context for retrieving it later