{"record":{"id":"d29ede5fa4c11f90","repo":"apache/cassandra","slug":"failed-to-close-zstddictcompress","errorCode":null,"errorMessage":"Failed to close ZstdDictCompress","messagePattern":"Failed to close ZstdDictCompress","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/db/compression/ZstdCompressionDictionary.java","lineNumber":281,"sourceCode":"         * 3. Once refcount is negative, tryRef() returns null, preventing new references\n         *\n         * Therefore, no synchronization is needed - we have exclusive access to clean up.\n         */\n        @Override\n        public void tidy()\n        {\n            // Close all compression dictionaries\n            // No synchronization needed - reference counting ensures exclusive access\n            for (ZstdDictCompress compressDict : zstdDictCompressPerLevel.values())\n            {\n                try\n                {\n                    compressDict.close();\n                }\n                catch (Exception e)\n                {\n                    // Log but don't fail - continue closing other resources\n                    logger.warn(\"Failed to close ZstdDictCompress\", e);\n                }\n            }\n            zstdDictCompressPerLevel.clear();\n\n            // Close decompression dictionary\n            ZstdDictDecompress decompressDict = dictDecompress.get();\n            if (decompressDict != null)\n            {\n                try\n                {\n                    decompressDict.close();\n                }\n                catch (Exception e)\n                {\n                    logger.warn(\"Failed to close ZstdDictDecompress\", e);\n                }\n                dictDecompress.set(null);\n            }","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compression/ZstdCompressionDictionary.java#L263-L299","documentation":"Logged by ZstdCompressionDictionary's Tidyable/Ref tidy method when closing the per-thread ZstdDictCompress native resource throws an exception. The code deliberately swallows the exception and logs a warning so the remaining resources (per-level dicts, decompression dict) still get closed. It signals a native zstd dictionary was not cleanly released, potentially leaking native memory.","triggerScenarios":"A compressed sstable's shared compression dictionary is being discarded (table drop, sstable compaction, dictionary replacement) and ZstdDictCompress.close() on the underlying zstd native handle throws; JVM shutdown or cache eviction triggers tidy on a dictionary whose native buffer was already freed or is in use.","commonSituations":"Table drops with zstd dictionary compression; heavy compaction activity churning dictionaries; native library state inconsistencies after close attempts; monitoring native memory leaks after such warnings.","solutions":["Treat a single occurrence as benign noise unless accompanied by native memory growth (check Native/ByteBuf memory metrics).","If repeated, verify the zstd JNI/native library version bundled with Cassandra matches the release (no mixed libzstd on the system library path).","Check for concurrent access to the dictionary during close (ensure the dictionary is truly unreferenced; avoid manually dropping refs).","If native memory leaks correlate with these warnings, capture logs and report to the project; restart affected node to reclaim leaked native memory."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    dict.close();\n} catch (Exception e) {\n    logger.warn(\"Failed to close ZstdDictCompress\", e); // swallow, continue cleanup\n}","preventionTips":["Monitor native (non-heap) memory for growth after these warnings.","Avoid manually forcing dictionary eviction; let reference counting drive cleanup.","Keep Cassandra's bundled zstd native library path clean of conflicting system libzstd.","Alert on repetition rate, not single occurrences."],"tags":["cassandra","zstd","compression","resource-cleanup","native"],"backgroundTag":"resource-cleanup-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}