{"record":{"id":"6dc715d56ba2f7bb","repo":"apache/cassandra","slug":"exception-thrown-when-cleaning-up-files-to-delete","errorCode":null,"errorMessage":"Exception thrown when cleaning up files to delete on exit, continuing.","messagePattern":"Exception thrown when cleaning up files to delete on exit, continuing\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/io/util/PathUtils.java","lineNumber":691,"sourceCode":"        private static void runOnExitThreadsAndClear()\n        {\n            List<Thread> toRun;\n            synchronized (onExitThreads)\n            {\n                toRun = new ArrayList<>(onExitThreads);\n                onExitThreads.clear();\n            }\n            Runtime runtime = Runtime.getRuntime();\n            toRun.forEach(onExitThread -> {\n                try\n                {\n                    runtime.removeShutdownHook(onExitThread);\n                    //noinspection CallToThreadRun\n                    onExitThread.run();\n                }\n                catch (Exception ex)\n                {\n                    logger.warn(\"Exception thrown when cleaning up files to delete on exit, continuing.\", ex);\n                }\n            });\n        }\n\n        private static void clearOnExitThreads()\n        {\n            synchronized (onExitThreads)\n            {\n                Runtime runtime = Runtime.getRuntime();\n                onExitThreads.forEach(runtime::removeShutdownHook);\n                onExitThreads.clear();\n            }\n        }\n\n        DeleteOnExit()\n        {\n            final Thread onExitThread = new Thread(this); // checkstyle: permit this instantiation\n            synchronized (onExitThreads)","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/PathUtils.java#L673-L709","documentation":"At shutdown, PathUtils runs the on-exit deletion threads to remove files registered for delete-on-exit. If running those threads (or removing the shutdown hook) throws, it logs this warning and continues shutdown anyway.","triggerScenarios":"JVM shutdown with files registered via File.deleteOnExit-style tracking, where the cleanup thread's run() throws (e.g. files already deleted, filesystem unavailable, hook issues).","commonSituations":"Node shutdown after a crash or forceful kill leaving stale registrations; temp/sandbox files already removed before exit; unclean filesystem state at shutdown.","solutions":["Verify no leftover temp files remain and delete them manually if needed","Check the attached stack trace for the failing cleanup step","Ignore if it occurs only at shutdown and no files remain","Investigate what deleted the files before the hook ran if it recurs"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    PathUtils.deleteOnExitIfEmpty(dir); // or equivalent registration\n} catch (Exception e) {\n    log.warn(\"could not register delete-on-exit; schedule manual cleanup\", e);\n}","preventionTips":["Do not rely on delete-on-exit for critical cleanup; clean up explicitly","Check for leftover temp files after unclean shutdowns","Investigate what removes registered files before the shutdown hook runs","Treat shutdown-time cleanup failures as best-effort and verify state at startup"],"tags":["io","filesystem","shutdown","cleanup"],"backgroundTag":"file-delete-failed","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"}