Skip to content

Commit 25e05b0

Browse files
Fix X-Pack SchedulerEngine Shutdown (#48951) (#49054)
We can have a race here where `scheduleNextRun` executes concurrently to `stop` and so we run into a `RejectedExecutionException` that we don't catch and thus it fails tests. => Fixed by ignoring these so long as they coincide with a scheduler shutdown
1 parent 095c343 commit 25e05b0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/scheduler/SchedulerEngine.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Set;
2626
import java.util.concurrent.CopyOnWriteArrayList;
2727
import java.util.concurrent.Executors;
28+
import java.util.concurrent.RejectedExecutionException;
2829
import java.util.concurrent.ScheduledExecutorService;
2930
import java.util.concurrent.ScheduledFuture;
3031
import java.util.concurrent.TimeUnit;
@@ -226,7 +227,14 @@ private void scheduleNextRun(long currentTime) {
226227
this.scheduledTime = schedule.nextScheduledTimeAfter(startTime, currentTime);
227228
if (scheduledTime != -1) {
228229
long delay = Math.max(0, scheduledTime - currentTime);
229-
future = scheduler.schedule(this, delay, TimeUnit.MILLISECONDS);
230+
try {
231+
future = scheduler.schedule(this, delay, TimeUnit.MILLISECONDS);
232+
} catch (RejectedExecutionException e) {
233+
// ignoring rejections if the scheduler has been shut down already
234+
if (scheduler.isShutdown() == false) {
235+
throw e;
236+
}
237+
}
230238
}
231239
}
232240

0 commit comments

Comments
 (0)