From 9ff11f1d35dd74c910887c1a176d015672b45629 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Tue, 24 Mar 2026 13:53:37 -0700 Subject: [PATCH] [FIX] Fix IllegalThreadStateException in ComponentStarter shutdown hook 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. --- .../bookkeeper/common/component/ComponentStarter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java index d1cb08163c5..b8dfced36d5 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/component/ComponentStarter.java @@ -76,7 +76,12 @@ public static CompletableFuture startComponent(LifecycleComponent componen component.getName(), t, e); System.err.println(e.getMessage()); // start the shutdown hook when an uncaught exception happen in the lifecycle component. - shutdownHookThread.start(); + try { + shutdownHookThread.start(); + } catch (IllegalThreadStateException ise) { + // the shutdown hook thread is already running (e.g. triggered by a prior + // exception or by the JVM shutdown sequence), so there is nothing else to do. + } }); component.publishInfo(new ComponentInfoPublisher());