Skip to content

Commit

Permalink
Fix Deadlock from Thread.suspend in Test (elastic#39261)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
original-brownbear authored and weizijun committed Feb 22, 2019
1 parent 16c4e2d commit 7991981
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ protected Pattern[] getUnsafeClasses() {
final LockedExecutor lockedExecutor = new LockedExecutor();
final AtomicLong ops = new AtomicLong();
final Thread[] threads = new Thread[5];
final Runnable yieldAndIncrement = () -> {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
};
try {
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
for (int iter = 0; stop.get() == false; iter++) {
if (iter % 2 == 0) {
lockedExecutor.executeLocked(() -> {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
});
lockedExecutor.executeLocked(yieldAndIncrement);
} else {
Thread.yield(); // give some chance to catch this stack trace
ops.incrementAndGet();
yieldAndIncrement.run();
}
}
});
Expand Down

0 comments on commit 7991981

Please sign in to comment.