Skip to content

Commit 525bf40

Browse files
Fix Deadlock from Thread.suspend in Test (elastic#39261)
* The lambda invoked by the `lockedExecutor` eventually gets JITed (which runs a static initializer that we will suspend in with a very tiny chance). * Fixed by creating the `Runnable` in the main test thread and using the same instance in all threads * Closes elastic#35686
1 parent 4df02a3 commit 525bf40

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/framework/src/test/java/org/elasticsearch/test/disruption/LongGCDisruptionTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,18 @@ protected Pattern[] getUnsafeClasses() {
127127
final LockedExecutor lockedExecutor = new LockedExecutor();
128128
final AtomicLong ops = new AtomicLong();
129129
final Thread[] threads = new Thread[5];
130+
final Runnable yieldAndIncrement = () -> {
131+
Thread.yield(); // give some chance to catch this stack trace
132+
ops.incrementAndGet();
133+
};
130134
try {
131135
for (int i = 0; i < threads.length; i++) {
132136
threads[i] = new Thread(() -> {
133137
for (int iter = 0; stop.get() == false; iter++) {
134138
if (iter % 2 == 0) {
135-
lockedExecutor.executeLocked(() -> {
136-
Thread.yield(); // give some chance to catch this stack trace
137-
ops.incrementAndGet();
138-
});
139+
lockedExecutor.executeLocked(yieldAndIncrement);
139140
} else {
140-
Thread.yield(); // give some chance to catch this stack trace
141-
ops.incrementAndGet();
141+
yieldAndIncrement.run();
142142
}
143143
}
144144
});

0 commit comments

Comments
 (0)