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

Remove thread sticky context feature #5436

Merged
merged 1 commit into from
Jan 8, 2025
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
6 changes: 0 additions & 6 deletions vertx-core/src/main/java/io/vertx/core/impl/VertxImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ private static ThreadFactory virtualThreadFactory() {
private final Throwable transportUnavailabilityCause;
private final VertxTracer tracer;
private final ThreadLocal<WeakReference<EventLoop>> stickyEventLoop = new ThreadLocal<>();
private final ThreadLocal<WeakReference<ContextInternal>> stickyContext = new ThreadLocal<>();
private final boolean disableTCCL;
private final Boolean useDaemonThread;

Expand Down Expand Up @@ -521,7 +520,6 @@ public void execute(Runnable command) {
} else {
ctx = createEventLoopContext(eventLoop, workerPool, Thread.currentThread().getContextClassLoader());
}
stickyContext.set(new WeakReference<>(ctx));
return ctx;
}
}
Expand Down Expand Up @@ -706,10 +704,6 @@ private ContextInternal getContext(Thread thread) {
return new ShadowContext(this, new EventLoopExecutor(eventLoop), context);
}
} else {
WeakReference<ContextInternal> ref = stickyContext.get();
if (ref != null) {
return ref.get();
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,8 @@ public void testFailedFutureContextPropagation2() {
}

@Test
public void testSticky() {
public void testStickiness() {
Context ctx = vertx.getOrCreateContext();
assertSame(ctx, vertx.getOrCreateContext());
assertSame(((ContextInternal)ctx).nettyEventLoop(), ((ContextInternal)vertx.getOrCreateContext()).nettyEventLoop());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public void testExecuteTasks() {
toRun.pop().run();
assertEquals(1, cnt[0]);
assertNull(Vertx.currentContext());
// Sticky context
assertSame(ctx, vertx.getOrCreateContext());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,28 @@ public void testUnordered() throws Exception {
}

@Test
public void testUseDifferentExecutorWithSameTaskQueue() throws Exception {
public void testUseDifferentExecutorWithSameTaskQueue() {
int count = 10;
waitFor(count);
WorkerExecutor exec = vertx.createSharedWorkerExecutor("vert.x-the-executor");
Thread startThread = Thread.currentThread();
AtomicReference<Thread> currentThread = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
for (int i = 0;i < count;i++) {
int val = i;
exec.executeBlocking(() -> {
Thread current = Thread.currentThread();
assertNotSame(startThread, current);
if (val == 0) {
assertNull(currentThread.getAndSet(current));
awaitLatch(latch);
} else {
assertSame(current, currentThread.get());
}
return null;
}, true).onComplete(onSuccess(v -> complete()));
latch.countDown();
}
vertx.runOnContext(v1 -> {
AtomicReference<Thread> currentThread = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
for (int i = 0;i < count;i++) {
int val = i;
exec.executeBlocking(() -> {
Thread current = Thread.currentThread();
if (val == 0) {
assertNull(currentThread.getAndSet(current));
awaitLatch(latch);
} else {
assertSame(current, currentThread.get());
}
return null;
}, true).onComplete(onSuccess(v2 -> complete()));
latch.countDown();
}
});
await();
}

Expand Down
Loading