diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java index a4a96db92b..0fed93e03d 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java @@ -29,7 +29,6 @@ import io.quarkus.deployment.annotations.Produce; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.BootstrapConfigSetupCompleteBuildItem; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; -import io.quarkus.deployment.builditem.ExecutorBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; @@ -567,7 +566,7 @@ class KeycloakProcessor { @Record(ExecutionTime.RUNTIME_INIT) @BuildStep - void initializeFilter(BuildProducer filters, KeycloakRecorder recorder, ExecutorBuildItem executor, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { + void initializeFilter(BuildProducer filters, KeycloakRecorder recorder, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { List ignoredPaths = new ArrayList<>(); @@ -583,7 +582,7 @@ class KeycloakProcessor { .orElse(QUARKUS_DEFAULT_METRICS_PATH))); } - filters.produce(new FilterBuildItem(recorder.createRequestFilter(ignoredPaths, executor.getExecutorProxy()),FilterBuildItem.AUTHORIZATION - 10)); + filters.produce(new FilterBuildItem(recorder.createRequestFilter(ignoredPaths),FilterBuildItem.AUTHORIZATION - 10)); } @BuildStep diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakRecorder.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakRecorder.java index d5e15eead2..c333f8ae54 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakRecorder.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakRecorder.java @@ -20,7 +20,6 @@ package org.keycloak.quarkus.runtime; import java.lang.annotation.Annotation; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutorService; import java.util.function.BiConsumer; import java.util.function.Predicate; @@ -142,8 +141,8 @@ public class KeycloakRecorder { }; } - public QuarkusRequestFilter createRequestFilter(List ignoredPaths, ExecutorService executor) { - return new QuarkusRequestFilter(createIgnoredHttpPathsPredicate(ignoredPaths), executor); + public QuarkusRequestFilter createRequestFilter(List ignoredPaths) { + return new QuarkusRequestFilter(createIgnoredHttpPathsPredicate(ignoredPaths)); } private Predicate createIgnoredHttpPathsPredicate(List ignoredPaths) { diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/web/QuarkusRequestFilter.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/web/QuarkusRequestFilter.java index e91af33ba5..d9e5728db1 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/web/QuarkusRequestFilter.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/web/QuarkusRequestFilter.java @@ -17,7 +17,6 @@ package org.keycloak.quarkus.runtime.integration.web; -import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.LongAdder; import java.util.function.Predicate; @@ -53,17 +52,14 @@ public class QuarkusRequestFilter implements Handler, Transactio private final Logger logger = Logger.getLogger(QuarkusRequestFilter.class); - private final ExecutorService executor; - - private Predicate contextFilter; + private final Predicate contextFilter; public QuarkusRequestFilter() { - this(null, null); + this(null); } - public QuarkusRequestFilter(Predicate contextFilter, ExecutorService executor) { + public QuarkusRequestFilter(Predicate contextFilter) { this.contextFilter = contextFilter; - this.executor = executor; } private final LongAdder rejectedRequests = new LongAdder(); @@ -78,7 +74,18 @@ public class QuarkusRequestFilter implements Handler, Transactio // our code should always be run as blocking until we don't provide a better support for running non-blocking code // in the event loop try { - executor.execute(createBlockingHandler(context)); + // When running in Quarkus dev mode, this will run on Vert.x default worker pool. + // When running in Quarkus production mode, this will run on the Quarkus executor pool. + // It should not call the Quarkus executor directly, as this prevents metrics for `worker_pool_*` to be collected. + // See https://github.com/quarkusio/quarkus/issues/34998 for a discussion. + context.vertx().executeBlocking(ctx -> { + try { + runBlockingCode(context); + ctx.complete(); + } catch (Throwable ex) { + ctx.fail(ex); + } + }, false, null); if (loadSheddingActive) { synchronized (rejectedRequests) { if (loadSheddingActive) { @@ -107,22 +114,20 @@ public class QuarkusRequestFilter implements Handler, Transactio return contextFilter != null && contextFilter.test(context); } - private Runnable createBlockingHandler(RoutingContext context) { - return () -> { - KeycloakSession session = configureContextualData(context); + private void runBlockingCode(RoutingContext context) { + KeycloakSession session = configureContextualData(context); - try { - context.next(); - } catch (Throwable cause) { - // re-throw so that the any exception is handled from parent - throw new RuntimeException(cause); - } finally { - // force closing the session if not already closed - // under some circumstances resteasy might not be invoked like when no route is found for a particular path - // in this case context is set with status code 404, and we need to close the session - close(session); - } - }; + try { + context.next(); + } catch (Throwable cause) { + // re-throw so that the any exception is handled from parent + throw new RuntimeException(cause); + } finally { + // force closing the session if not already closed + // under some circumstances resteasy might not be invoked like when no route is found for a particular path + // in this case context is set with status code 404, and we need to close the session + close(session); + } } private KeycloakSession configureContextualData(RoutingContext context) {