{"record":{"id":"f66fb92a65cbe255","repo":"vectordotdev/vector","slug":"failed-to-write-to-encoder","errorCode":null,"errorMessage":"failed to write to encoder","messagePattern":"failed to write to encoder","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/codecs/src/decoding/framing/chunked_gelf.rs","lineNumber":691,"sourceCode":"        Zlib,\n    }\n\n    impl Compression {\n        pub fn compress(&self, payload: &impl AsRef<[u8]>) -> Bytes {\n            self.compress_with_level(payload, flate2::Compression::default())\n        }\n\n        pub fn compress_with_level(\n            &self,\n            payload: &impl AsRef<[u8]>,\n            level: flate2::Compression,\n        ) -> Bytes {\n            match self {\n                Compression::Gzip => {\n                    let mut encoder = GzEncoder::new(Vec::new(), level);\n                    encoder\n                        .write_all(payload.as_ref())\n                        .expect(\"failed to write to encoder\");\n                    encoder.finish().expect(\"failed to finish encoder\").into()\n                }\n                Compression::Zlib => {\n                    let mut encoder = ZlibEncoder::new(Vec::new(), level);\n                    encoder\n                        .write_all(payload.as_ref())\n                        .expect(\"failed to write to encoder\");\n                    encoder.finish().expect(\"failed to finish encoder\").into()\n                }\n            }\n        }\n    }\n\n    fn create_chunk(\n        message_id: u64,\n        sequence_number: u8,\n        total_chunks: u8,\n        payload: &impl AsRef<[u8]>,","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/codecs/src/decoding/framing/chunked_gelf.rs#L673-L709","documentation":"The chunked GELF decompression helper `compress_with_level` writes the payload into a `GzEncoder` wrapping an in-memory `Vec<u8>` and `expect`s the write to succeed. Writing to a `Vec` cannot realistically fail (no I/O), so this panic indicates an internal zlib/flate2 error rather than a user-fixable condition.","triggerScenarios":"`compress_with_level` (called by `compress`) invoking `write_all` on a `GzEncoder` when the underlying flate2/zlib stream returns an unexpected error — e.g. an allocation failure or a flate2 backend (miniz/zlib-ng) internal fault.","commonSituations":"Extremely rare; seen under memory exhaustion or when using an exotic flate2 backend feature combination. GELF chunk compression of UDP payloads is the call path.","solutions":["Check system memory availability — allocation failure is the most plausible cause","Try a different flate2 backend (e.g. switch the `flate2` default feature to `rust_backend` or `zlib-ng`)","Update flate2 and Vector to current versions","If maintainable, propagate the error instead of `expect`-panicking"],"exampleFix":"// before\nencoder.write_all(payload.as_ref()).expect(\"failed to write to encoder\");\n// after\nencoder.write_all(payload.as_ref())\n    .expect(\"in-memory compression write cannot fail unless OOM\");","handlingStrategy":"try-catch","validationCode":"// Rust: preflight capacity before compressing\nlet estimated = payload.len() + 64;\nassert!(estimated <= available_memory_hint(), \"insufficient memory for gzip buffer\");","typeGuard":"fn compressible(payload: &[u8], level: CompressionLevel) -> bool {\n    // in-memory writes cannot fail except under OOM; guard size\n    payload.len() <= MAX_GELF_CHUNK_PAYLOAD\n}","tryCatchPattern":"match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| compress(payload, level))) {\n    Ok(bytes) => bytes,\n    Err(_) => { /* log OOM suspicion; fall back to uncompressed path or drop chunk */ }\n}","preventionTips":["Ensure adequate host memory; allocation failure is the realistic trigger","Test with different flate2 backends if panics reproduce","Keep flate2 and Vector updated","Consider error propagation instead of expect in compression helpers"],"tags":["rust","gzip","compression","flate2","gelf"],"backgroundTag":"compression-write-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}