{"record":{"id":"7842275d89f97264","repo":"apache/cassandra","slug":"hintsservice-has-already-been-shut-down","errorCode":null,"errorMessage":"HintsService has already been shut down","messagePattern":"HintsService has already been shut down","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/hints/HintsService.java","lineNumber":325,"sourceCode":"        for (HintsStore store : catalog.storesCollection())\n        {\n            if (store == null)\n                continue;\n            size += store.getTotalFileSize();\n        }\n        return size;\n    }\n\n    /**\n     * Gracefully and blockingly shut down the service.\n     *\n     * Will abort dispatch sessions that are currently in progress (which is okay, it's idempotent),\n     * and make sure the buffers are flushed, hints files written and fsynced.\n     */\n    public synchronized void shutdownBlocking() throws ExecutionException, InterruptedException\n    {\n        if (isShutDown)\n            throw new IllegalStateException(\"HintsService has already been shut down\");\n        isShutDown = true;\n\n        if (triggerDispatchFuture != null)\n            triggerDispatchFuture.cancel(false);\n        pauseDispatch();\n\n        triggerFlushingFuture.cancel(false);\n\n        triggerCleanupFuture.cancel(false);\n\n        writeExecutor.flushBufferPool(bufferPool).get();\n        writeExecutor.closeAllWriters().get();\n\n        dispatchExecutor.shutdownBlocking();\n        writeExecutor.shutdownBlocking();\n\n        HintsServiceDiagnostics.dispatchingShutdown(this);\n        bufferPool.close();","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/hints/HintsService.java#L307-L343","documentation":"Fired in HintsService.shutdownBlocking when isShutDown is already true: shutdown is requested a second time. The service is idempotent-guarded — instead of double-shutting down executors, it throws IllegalStateException('HintsService has already been shut down') to signal misuse of the lifecycle API.","triggerScenarios":"Calling HintsService.shutdownBlocking() twice — e.g. shutdown hooks and StorageService shutdown both invoking it, or test code shutting down the service and then the node also doing so.","commonSituations":"Double shutdown via both JVM shutdown hook and explicit stop; batchlog-and-hints shutdown invoked after a prior manual shutdown in embedded/test setups.","solutions":["Track shutdown with your own flag or check isShutDown state before calling again","Catch IllegalStateException and ignore — the service is already stopped, which is the desired end state","Consolidate shutdown paths so only one component calls shutdownBatchlogAndHints","In tests, use the framework's cluster close() rather than manual shutdown"],"exampleFix":"// before\nHintsService.instance.shutdownBlocking();\n// after\ntry {\n    HintsService.instance.shutdownBlocking();\n} catch (IllegalStateException e) {\n    // already shut down — nothing to do\n}","handlingStrategy":"try-catch","validationCode":"// only call once per node lifecycle; track locally\nprivate final AtomicBoolean hintsShutdownDone = new AtomicBoolean(false);\nif (!hintsShutdownDone.compareAndSet(false, true)) return;","typeGuard":null,"tryCatchPattern":"try {\n    HintsService.instance.shutdownBlocking();\n} catch (IllegalStateException e) {\n    // already shut down; safe to ignore\n}","preventionTips":["Route all shutdown through a single path (shutdownBatchlogAndHints)","Avoid mixing manual shutdown calls with JVM shutdown hooks","In embedded tests, rely on cluster.close()","Make shutdown idempotent in your orchestration code"],"tags":["lifecycle","shutdown","idempotency","hints"],"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"}