{"record":{"id":"9e14119218b671cb","repo":"apache/cassandra","slug":"executor-has-shut-down","errorCode":null,"errorMessage":"${executor} has shut down","messagePattern":"(.+?) has shut down","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/concurrent/ThreadPoolExecutorBase.java","lineNumber":54,"sourceCode":" * <li>Tasks rejected due to overflow of the queue block the submitting thread rather than throwing {@link RejectedExecutionException}\n * <li>{@link RunnableFuture} rejected due to executor shutdown will be cancelled\n * <li>{@link RunnableFuture} removed by {@link #shutdownNow()} will be cancelled\n *\n * We also provide a shutdown hook for JMX registration cleanup.\n */\npublic class ThreadPoolExecutorBase extends ThreadPoolExecutor implements ResizableThreadPool\n{\n    public static final RejectedExecutionHandler blockingExecutionHandler = (task, executor) ->\n    {\n        BlockingQueue<Runnable> queue = executor.getQueue();\n        try\n        {\n            while (true)\n            {\n                try\n                {\n                    if (executor.isShutdown())\n                        throw new RejectedExecutionException(executor + \" has shut down\");\n\n                    if (queue.offer(task, 1, TimeUnit.SECONDS))\n                        break;\n                }\n                catch (InterruptedException e)\n                {\n                    throw new UncheckedInterruptedException(e);\n                }\n            }\n        }\n        catch (Throwable t)\n        {\n            //Give some notification to the caller the task isn't going to run\n            if (task instanceof java.util.concurrent.Future)\n                ((java.util.concurrent.Future<?>) task).cancel(false);\n            throw t;\n        }\n    };","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/concurrent/ThreadPoolExecutorBase.java#L36-L72","documentation":"Thrown as a RejectedExecutionException by ThreadPoolExecutorBase when a task is submitted to an executor that has already been shut down. The submission loop first checks executor.isShutdown() and rejects rather than queueing into a dead pool.","triggerScenarios":"Calling executor.execute()/submit() after shutdown() or shutdownNow() was invoked, typically during node shutdown, decommission, or stop of a service holding the executor.","commonSituations":"Background daemons or callbacks firing during Cassandra shutdown, tests tearing down clusters while async work is still submitting, race between a scheduler and lifecycle shutdown hooks.","solutions":["Stop producers before calling shutdown(), or add a terminated flag producers check before submitting","Catch RejectedExecutionException around submit and treat it as 'dropped during shutdown'","Use a longer-lived executor or delay shutdown until pending work completes","Guard submissions with ExecutorService.isShutdown() checks at the call site"],"exampleFix":"// before\nexecutor.submit(() -> handle(message));\n// after\ntry\n{\n    executor.submit(() -> handle(message));\n}\ncatch (RejectedExecutionException e)\n{\n    logger.debug(\"Executor shut down, dropping task\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (executor.isShutdown()) { logger.warn(\"Executor shut down; skipping submit\"); return; }","typeGuard":null,"tryCatchPattern":"try {\n    executor.submit(task);\n} catch (RejectedExecutionException e) {\n    logger.debug(\"Task dropped because executor shut down\", e);\n}","preventionTips":["Stop task producers before calling shutdown()","Track executor lifecycle with a volatile terminated flag","Treat RejectedExecutionException as benign during shutdown paths"],"tags":["concurrency","threadpool","shutdown"],"backgroundTag":"invalid-state-transition","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}