From cc4aef5dd9eb7a451f5488568fe62dc70fa575bc Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Fri, 29 Apr 2022 16:27:31 +0200 Subject: [PATCH] Scheduled methods - mark vertx context as safe - fixes #25257 --- .../io/quarkus/quartz/runtime/QuartzScheduler.java | 12 ++++++++---- .../quarkus/scheduler/runtime/SimpleScheduler.java | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java index d04ae8ab00a34..ec68f58ae0025 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java @@ -73,7 +73,9 @@ import io.quarkus.scheduler.common.runtime.StatusEmitterInvoker; import io.quarkus.scheduler.common.runtime.util.SchedulerUtils; import io.quarkus.scheduler.runtime.SchedulerRuntimeConfig; +import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle; import io.smallrye.common.vertx.VertxContext; +import io.vertx.core.Context; import io.vertx.core.Handler; import io.vertx.core.Vertx; @@ -555,20 +557,22 @@ static class InvokerJob implements Job { } @Override - public void execute(JobExecutionContext context) throws JobExecutionException { + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { if (trigger.invoker != null) { // could be null from previous runs if (trigger.invoker.isBlocking()) { try { - trigger.invoker.invoke(new QuartzScheduledExecution(trigger, context)); + trigger.invoker.invoke(new QuartzScheduledExecution(trigger, jobExecutionContext)); } catch (Exception e) { throw new JobExecutionException(e); } } else { - VertxContext.getOrCreateDuplicatedContext(vertx).runOnContext(new Handler() { + Context context = VertxContext.getOrCreateDuplicatedContext(vertx); + VertxContextSafetyToggle.setContextSafe(context, true); + context.runOnContext(new Handler() { @Override public void handle(Void event) { try { - trigger.invoker.invoke(new QuartzScheduledExecution(trigger, context)); + trigger.invoker.invoke(new QuartzScheduledExecution(trigger, jobExecutionContext)); } catch (Exception e) { // already logged by the StatusEmitterInvoker } diff --git a/extensions/scheduler/runtime/src/main/java/io/quarkus/scheduler/runtime/SimpleScheduler.java b/extensions/scheduler/runtime/src/main/java/io/quarkus/scheduler/runtime/SimpleScheduler.java index 15adc72b52b1e..40a2bf2af9dd9 100644 --- a/extensions/scheduler/runtime/src/main/java/io/quarkus/scheduler/runtime/SimpleScheduler.java +++ b/extensions/scheduler/runtime/src/main/java/io/quarkus/scheduler/runtime/SimpleScheduler.java @@ -51,6 +51,7 @@ import io.quarkus.scheduler.common.runtime.SkipPredicateInvoker; import io.quarkus.scheduler.common.runtime.StatusEmitterInvoker; import io.quarkus.scheduler.common.runtime.util.SchedulerUtils; +import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle; import io.smallrye.common.vertx.VertxContext; import io.vertx.core.Context; import io.vertx.core.Handler; @@ -319,6 +320,7 @@ public void run() { } } else { Context context = VertxContext.getOrCreateDuplicatedContext(vertx); + VertxContextSafetyToggle.setContextSafe(context, true); context.runOnContext(new Handler() { @Override public void handle(Void event) {