{"record":{"id":"605ad85ececfee5b","repo":"apache/cassandra","slug":"scheduler-has-shut-down","errorCode":null,"errorMessage":"Scheduler has shut down.","messagePattern":"Scheduler has shut down\\.","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/service/accord/api/AccordScheduler.java","lineNumber":85,"sourceCode":"    public Scheduled once(Runnable run, long delay, TimeUnit units)\n    {\n        ScheduledFuture<?> future = scheduledExecutor.schedule(run, delay, units);\n        return new ScheduledFutureWrapper(future);\n    }\n\n    @Override\n    public Scheduled selfRecurring(Runnable run, long delay, TimeUnit units)\n    {\n        ScheduledFuture<?> future = scheduledExecutor.scheduleSelfRecurring(run, delay, units);\n        return new ScheduledFutureWrapper(future);\n    }\n\n    @Override\n    public void now(Runnable task)\n    {\n        // called from the mutation stage configured by the verb\n        if (scheduledExecutor.isShutdown())\n            throw new RejectedExecutionException(\"Scheduler has shut down.\");\n        scheduledExecutor.submit(task);\n    }\n\n    @Override\n    public boolean isTerminated()\n    {\n        return scheduledExecutor.isTerminated();\n    }\n\n    @Override\n    public void shutdown()\n    {\n        for (Runnable c : shutdownNow())\n        {\n            if (c instanceof java.util.concurrent.Future<?>)\n                ((java.util.concurrent.Future<?>) c).cancel(false);\n        }\n    }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/accord/api/AccordScheduler.java#L67-L103","documentation":"AccordScheduler.now(Runnable) submits a task to run immediately on its scheduled executor. If the executor has already been shut down (node shutdown/decommission of the Accord service), submit() would be rejected, so the method explicitly throws RejectedExecutionException('Scheduler has shut down.'). This indicates work was scheduled during or after Accord teardown.","triggerScenarios":"Calling AccordScheduler.now(task) after Scheduler shutdown began — e.g. a mutation-stage verb or timer callback firing while the node is shutting down, decommissioning, or Accord is being stopped.","commonSituations":"In-flight transactional work racing node shutdown/decommission; tests that tear down the cluster while timers still fire; restart/stop scripts executed while Accord tasks are pending; error handling paths that schedule retries post-shutdown.","solutions":["Check scheduler.isTerminated()/isShutdown() (or catch RejectedExecutionException) before/when scheduling and drop the task during shutdown","Ensure node shutdown quiesces transactional/mutation-stage work before stopping the Accord scheduler","In tests, close clusters only after all in-flight async work completes","Re-submit the task if the scheduler is expected to be restarted, or route the work to a valid executor"],"exampleFix":"// before\nscheduler.now(task);\n// after\ntry\n{\n    scheduler.now(task);\n}\ncatch (RejectedExecutionException e)\n{\n    logger.info(\"Dropping task {}; scheduler has shut down\", task, e);\n}","handlingStrategy":"try-catch","validationCode":"if (scheduler.isTerminated() || scheduler.isShutdown()) { logger.info(\"Scheduler shut down; dropping task\"); return; }","typeGuard":"boolean canSchedule(AccordScheduler s) { return !s.isShutdown() && !s.isTerminated(); }","tryCatchPattern":"try { scheduler.now(task); } catch (RejectedExecutionException e) { logger.debug(\"Task dropped after scheduler shutdown\", e); }","preventionTips":["Quiesce in-flight Accord work before stopping the scheduler","Catch RejectedExecutionException around any post-shutdown scheduling","In tests, close clusters only after async work drains","Avoid scheduling retries/cleanup from shutdown hooks via AccordScheduler"],"tags":["scheduler","shutdown","rejected-execution","accord","lifecycle"],"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"}