Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When propagating the duplicated context, drop the request scope #29036

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand All @@ -27,7 +29,7 @@ private static final class VertxCurrentContext<T extends ContextState> implement
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();
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand Down