{"record":{"id":"22bd76e22207e903","repo":"vectordotdev/vector","slug":"max-zlib-compressed-frame-size-bytes-already-set","errorCode":null,"errorMessage":"max_zlib_compressed_frame_size_bytes already set","messagePattern":"max_zlib_compressed_frame_size_bytes already set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-common/src/decompression.rs","lineNumber":82,"sourceCode":"\nconst DEFAULT_MAX_ZLIB_COMPRESSED_FRAME_SIZE_BYTES: usize =\n    zlib_compressed_frame_limit(DEFAULT_MAX_DECOMPRESSED_SIZE_BYTES);\n\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)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-common/src/decompression.rs#L64-L100","documentation":"set_max_decompressed_size_bytes initializes three global OnceLocks in sequence: the main decompressed-size cap, then the derived zlib compressed-frame limit, then the zstd window-log max. This expect is on the second cell (the zlib frame limit). Through the public API it is unreachable on a double call, because the first cell's expect (error 117) panics before this line runs; it can only fire if internal misuse sets the cells out of order.","triggerScenarios":"MAX_ZLIB_COMPRESSED_FRAME_SIZE_BYTES.set() returning Err — requires the main cap to already be set while the zlib limit is not, which the single public setter (which sets them together and panics on the first) cannot produce; only direct internal misuse or a future second setter could.","commonSituations":"None through the public API; a double call to set_max_decompressed_size_bytes always panics at the first expect (error 117) instead.","solutions":["Apply the fix for the first cell: initialize once via a Once/OnceLock guard in your setup (see error 117)","If this exact line ever fires, report it upstream since it implies divergent internal initialization"],"exampleFix":"// before\nset_max_decompressed_size_bytes(a);\nset_max_decompressed_size_bytes(b); // panics (first at the main cap)\n\n// after\nstatic INIT: std::sync::Once = std::sync::Once::new();\nINIT.call_once(|| set_max_decompressed_size_bytes(a));","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","Do not add new call sites for set_max_decompressed_size_bytes; route all setup through one helper"],"tags":["rust","vector","decompression","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"}