Log uncaught exceptions from scheduled once tasks
`ScheduledThreadPoolExecutor` allows you to schedule tasks to run once or periodically at the future. If such a task throws an exception, that exception is caught and reported in the future that `ScheduledThreadPoolExecutor#schedule` returns. However, we typically do not capture the future / do not test it for errors. This results in exception being swallowed and not reported. To mitigate this we now wrap any command in a LoggingRunnable (already used for periodic tasks). Also, RunnableCommand is changed not to swallow exception but percolate them further for reporting by the future. Closes #15824
This commit is contained in:
parent
e7f9d685f1
commit
d5e6eb58a8
|
@ -357,7 +357,7 @@ public class ThreadPool extends AbstractComponent {
|
|||
if (!Names.SAME.equals(name)) {
|
||||
command = new ThreadedRunnable(command, executor(name));
|
||||
}
|
||||
return scheduler.schedule(command, delay.millis(), TimeUnit.MILLISECONDS);
|
||||
return scheduler.schedule(new LoggingRunnable(command), delay.millis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
@ -633,6 +633,7 @@ public class ThreadPool extends AbstractComponent {
|
|||
runnable.run();
|
||||
} catch (Throwable t) {
|
||||
logger.warn("failed to run {}", t, runnable.toString());
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue