Skip to content

Commit 6dc5925

Browse files
authored
[FIX] Fix IllegalThreadStateException in ComponentStarter shutdown hook (#4733)
The UncaughtExceptionHandler in ComponentStarter calls shutdownHookThread.start(), but this can throw IllegalThreadStateException if the thread was already started by a prior exception or by the JVM shutdown sequence. This exception propagates out of the handler, causing the JVM to print "Exception thrown from the UncaughtExceptionHandler" on the BookieDeathWatcher thread. Catch IllegalThreadStateException since it simply means shutdown is already in progress.
1 parent 8a8f4d6 commit 6dc5925

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ public static CompletableFuture<Void> startComponent(LifecycleComponent componen
7676
component.getName(), t, e);
7777
System.err.println(e.getMessage());
7878
// start the shutdown hook when an uncaught exception happen in the lifecycle component.
79-
shutdownHookThread.start();
79+
try {
80+
shutdownHookThread.start();
81+
} catch (IllegalThreadStateException ise) {
82+
// the shutdown hook thread is already running (e.g. triggered by a prior
83+
// exception or by the JVM shutdown sequence), so there is nothing else to do.
84+
}
8085
});
8186

8287
component.publishInfo(new ComponentInfoPublisher());

0 commit comments

Comments
 (0)