Repository: quarkusio/quarkus
Issue: Request Context Race condition in quarkus 2.13

### Describe the bug

when firing an async CDI Event, the request context from the emitter briefly exists for the observer and is then terminated.
This prevents to create a new Request context for the Async observer since the emitter context still exist.

This was working in Quarkus 2.12




### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

reproducer: 

https://github.com/rmanibus/quarkus_29017

execute the ReproducerTest

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.13.3.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java

diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java
index 05d88e50dbd..5ac0b5769c9 100644
--- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java
+++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java
@@ -17,6 +17,7 @@
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ThreadFactory;
@@ -42,7 +43,9 @@
 import io.quarkus.vertx.core.runtime.config.ClusterConfiguration;
 import io.quarkus.vertx.core.runtime.config.EventBusConfiguration;
 import io.quarkus.vertx.core.runtime.config.VertxConfiguration;
+import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle;
 import io.quarkus.vertx.mdc.provider.LateBoundMDCProvider;
+import io.quarkus.vertx.runtime.VertxCurrentContextFactory;
 import io.vertx.core.AsyncResult;
 import io.vertx.core.Context;
 import io.vertx.core.Handler;
@@ -558,7 +561,16 @@ public void runWith(Runnable task, Object context) {
                 ContextInternal currentContext = (ContextInternal) Vertx.currentContext();
                 if (context != null && context != currentContext) {
                     // Only do context handling if it's non-null
-                    final ContextInternal vertxContext = (ContextInternal) context;
+                    ContextInternal vertxContext = (ContextInternal) context;
+                    // The CDI request context must not be propagated
+                    ConcurrentMap<Object, Object> local = vertxContext.localContextData();
+                    if (local.containsKey(VertxCurrentContextFactory.LOCAL_KEY)) {
+                        // Duplicate the context, copy the data, remove the request context
+                        vertxContext = vertxContext.duplicate();
+                        vertxContext.localContextData().putAll(local);
+                        vertxContext.localContextData().remove(VertxCurrentContextFactory.LOCAL_KEY);
+                        VertxContextSafetyToggle.setContextSafe(vertxContext, true);
+                    }
                     vertxContext.beginDispatch();
                     try {
                         task.run();
diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
index a2806ebc628..88db266deac 100644
--- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
+++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
@@ -14,6 +14,8 @@
 
 public class VertxCurrentContextFactory implements CurrentContextFactory {
 
+    public static final String LOCAL_KEY = "io.quarkus.vertx.cdi-current-context";
+
     @Override
     public <T extends InjectableContext.ContextState> CurrentContext<T> create(Class<? extends Annotation> scope) {
         return new VertxCurrentContext<>();
@@ -27,7 +29,7 @@ public <T extends InjectableContext.ContextState> CurrentContext<T> create(Class
         public T get() {
             Context context = Vertx.currentContext();
             if (context != null && VertxContext.isDuplicatedContext(context)) {
-                return context.getLocal(this);
+                return context.getLocal(LOCAL_KEY);
             }
             return fallback.get();
         }
@@ -37,7 +39,7 @@ public void set(T state) {
             Context context = Vertx.currentContext();
             if (context != null && VertxContext.isDuplicatedContext(context)) {
                 VertxContextSafetyToggle.setContextSafe(context, true);
-                context.putLocal(this, state);
+                context.putLocal(LOCAL_KEY, state);
             } else {
                 fallback.set(state);
             }
@@ -48,7 +50,7 @@ public void remove() {
             Context context = Vertx.currentContext();
             if (context != null && VertxContext.isDuplicatedContext(context)) {
                 // NOOP - the DC should not be shared.
-                //                context.removeLocal(this);
+                // context.removeLocal(LOCAL_KEY);
             } else {
                 fallback.remove();
             }