Skip to content

Commit 06726e1

Browse files
committed
[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 ff7ea0d commit 06726e1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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
@@ -75,7 +75,12 @@ public static CompletableFuture<Void> startComponent(LifecycleComponent componen
7575
log.error("Triggered exceptionHandler of Component: {} because of Exception in Thread: {}",
7676
component.getName(), t, e);
7777
// start the shutdown hook when an uncaught exception happen in the lifecycle component.
78-
shutdownHookThread.start();
78+
try {
79+
shutdownHookThread.start();
80+
} catch (IllegalThreadStateException ise) {
81+
// the shutdown hook thread is already running (e.g. triggered by a prior
82+
// exception or by the JVM shutdown sequence), so there is nothing else to do.
83+
}
7984
});
8085

8186
component.publishInfo(new ComponentInfoPublisher());

0 commit comments

Comments
 (0)