{"record":{"id":"a2b59ffc45ee1320","repo":"vectordotdev/vector","slug":"max-zstd-window-log-already-set","errorCode":null,"errorMessage":"max_zstd_window_log already set","messagePattern":"max_zstd_window_log already set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-common/src/decompression.rs","lineNumber":85,"sourceCode":"\nconst DEFAULT_MAX_ZSTD_WINDOW_LOG: Option<u32> =\n    zstd_window_log_max(DEFAULT_MAX_DECOMPRESSED_SIZE_BYTES);\n\n/// Override the global decompressed payload size cap. Must be called before any sources start.\n///\n/// # Panics\n///\n/// Panics if called more than once, as the global cap may only be initialized a single time.\npub fn set_max_decompressed_size_bytes(size: usize) {\n    MAX_DECOMPRESSED_SIZE_BYTES\n        .set(size)\n        .expect(\"max_decompressed_size_bytes already set\");\n    MAX_ZLIB_COMPRESSED_FRAME_SIZE_BYTES\n        .set(zlib_compressed_frame_limit(size))\n        .expect(\"max_zlib_compressed_frame_size_bytes already set\");\n    MAX_ZSTD_WINDOW_LOG\n        .set(zstd_window_log_max(size))\n        .expect(\"max_zstd_window_log already set\");\n}\n\n/// Returns the currently configured decompressed payload size cap.\npub fn max_decompressed_size_bytes() -> usize {\n    *MAX_DECOMPRESSED_SIZE_BYTES\n        .get()\n        .unwrap_or(&DEFAULT_MAX_DECOMPRESSED_SIZE_BYTES)\n}\n\n/// Returns the maximum compressed frame wire size we are willing to buffer, derived from the\n/// decompressed cap plus zlib's worst-case expansion. See `zlib_compressed_frame_limit`.\npub fn max_zlib_compressed_frame_size_bytes() -> usize {\n    *MAX_ZLIB_COMPRESSED_FRAME_SIZE_BYTES\n        .get()\n        .unwrap_or(&DEFAULT_MAX_ZLIB_COMPRESSED_FRAME_SIZE_BYTES)\n}\n\n/// Smallest zstd `window_log_max` capable of representing `max_decompressed_size` bytes.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-common/src/decompression.rs#L67-L103","documentation":"The third and final OnceLock initialized by set_max_decompressed_size_bytes holds the zstd window-log maximum derived from the decompressed cap. This expect is on that cell. Via the public API it is unreachable on a double call because the first cell's expect (error 117) panics earlier; it exists to guard the internal invariant that all three cells are initialized together, exactly once.","triggerScenarios":"MAX_ZSTD_WINDOW_LOG.set() returning Err — requires the main cap and zlib limit to be set while the zstd cell is not, which the single sequential public setter cannot produce; only internal misuse or a refactor adding a divergent init path could trip it.","commonSituations":"None through the public API; double initialization always surfaces as the error-117 panic first.","solutions":["Apply the once-only initialization fix described for error 117","If this exact line fires, report it upstream — it indicates divergent internal initialization of the three cells"],"exampleFix":"// before\nset_max_decompressed_size_bytes(a);\nset_max_decompressed_size_bytes(b); // panics before reaching the zstd cell\n\n// after\nstatic INIT: std::sync::OnceLock<()> = std::sync::OnceLock::new();\nlet _ = INIT.set_or_init(()); // your own once-guard around the single setter call","handlingStrategy":"validation","validationCode":"static INIT: std::sync::Once = std::sync::Once::new();\n\nfn init_decompression_cap(size: usize) {\n    INIT.call_once(|| {\n        vector_common::decompression::set_max_decompressed_size_bytes(size);\n    });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply the same once-only initialization guard as for the main cap cell","Keep zstd-related configuration changes routed through the single documented setter call site"],"tags":["rust","vector","decompression","zstd","global-state","oncelock","panic"],"backgroundTag":"oncelock-already-initialized","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}