{"record":{"id":"d600dbe2bdd5ff47","repo":"Netflix/Hystrix","slug":"interrupted-while-waiting-for-thread-pools-to-term","errorCode":null,"errorMessage":"Interrupted while waiting for thread-pools to terminate. Pools may not be correctly shutdown or cleared.","messagePattern":"Interrupted while waiting for thread-pools to terminate\\. Pools may not be correctly shutdown or cleared\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java","lineNumber":151,"sourceCode":"        }\n\n        /**\n         * Initiate the shutdown of all {@link HystrixThreadPool} instances and wait up to the given time on each pool to complete.\n         * <p>\n         * NOTE: This is NOT thread-safe if HystrixCommands are concurrently being executed\n         * and causing thread-pools to initialize while also trying to shutdown.\n         * </p>\n         */\n        /* package */static synchronized void shutdown(long timeout, TimeUnit unit) {\n            for (HystrixThreadPool pool : threadPools.values()) {\n                pool.getExecutor().shutdown();\n            }\n            for (HystrixThreadPool pool : threadPools.values()) {\n                try {\n                    while (! pool.getExecutor().awaitTermination(timeout, unit)) {\n                    }\n                } catch (InterruptedException e) {\n                    throw new RuntimeException(\"Interrupted while waiting for thread-pools to terminate. Pools may not be correctly shutdown or cleared.\", e);\n                }\n            }\n            threadPools.clear();\n        }\n    }\n\n    /**\n     * @ExcludeFromJavadoc\n     * @ThreadSafe\n     */\n    /* package */static class HystrixThreadPoolDefault implements HystrixThreadPool {\n        private static final Logger logger = LoggerFactory.getLogger(HystrixThreadPoolDefault.class);\n\n        private final HystrixThreadPoolProperties properties;\n        private final BlockingQueue<Runnable> queue;\n        private final ThreadPoolExecutor threadPool;\n        private final HystrixThreadPoolMetrics metrics;\n        private final int queueSize;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java#L133-L169","documentation":"HystrixThreadPool.shutdown(timeout, unit) stops every pool and awaits termination; if a waiting thread is interrupted during awaitTermination, it throws RuntimeException('Interrupted while waiting for thread-pools to terminate. Pools may not be correctly shutdown or cleared.') and the static threadPools map is left uncleared.","triggerScenarios":"Calling Hystrix.shutdown() / HystrixThreadPool.shutdown() and having the calling thread receive an interrupt (shutdown hook racing JVM exit, another thread interrupting, container thread interruption during redeploy).","commonSituations":"Application shutdown hooks where Hystrix shutdown races with JVM teardown; servlet container hot redeploys interrupting cleanup threads; tests that time out and interrupt the thread running Hystrix shutdown.","solutions":["Restore the interrupt and retry shutdown: catch the RuntimeException, call Thread.currentThread().interrupt() is already-signal; re-invoke Hystrix.shutdown() with a longer/second attempt","Perform shutdown from a dedicated, non-interruptible cleanup path (e.g. contextDestroyed without container-imposed timeouts)","Increase the timeout passed to shutdown so awaitTermination finishes before any container deadline","Accept pooled-thread leakage at JVM exit (harmless when the process ends anyway) — only fix if the container keeps running"],"exampleFix":"// before\nRuntime.getRuntime().addShutdownHook(new Thread(() -> Hystrix.shutdown()));\n// after\nRuntime.getRuntime().addShutdownHook(new Thread(() -> {\n  try { Hystrix.reset(5, TimeUnit.SECONDS); }\n  catch (RuntimeException e) { Thread.currentThread().interrupt(); /* JVM exiting */ }\n}));","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"catch (RuntimeException e) { if (e.getMessage().startsWith(\"Interrupted while waiting for thread-pools\")) { Thread.currentThread().interrupt(); /* optional: retry Hystrix.reset once with a longer timeout */ } }","preventionTips":["Call Hystrix.reset()/shutdown() from a dedicated cleanup thread with adequate timeout","Drain in-flight commands before shutdown","Never rely on interrupt-driven container timeouts for Hystrix teardown"],"tags":["java","hystrix","shutdown","thread-pool","interruption"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}