{"record":{"id":"fc524da70f8a980e","repo":"vectordotdev/vector","slug":"gzip-writer-should-not-fail-to-finish","errorCode":null,"errorMessage":"gzip writer should not fail to finish","messagePattern":"gzip writer should not fail to finish","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/compressor.rs","lineNumber":39,"sourceCode":"impl Writer {\n    pub fn get_ref(&self) -> &BytesMut {\n        match self {\n            Writer::Plain(inner) => inner.get_ref(),\n            Writer::Gzip(inner) => inner.get_ref().get_ref().get_ref(),\n            Writer::Zlib(inner) => inner.get_ref().get_ref().get_ref(),\n            Writer::Zstd(inner) => inner.get_ref().get_ref(),\n            Writer::Snappy(inner) => inner.get_ref().get_ref(),\n        }\n    }\n\n    pub fn into_inner(self) -> BytesMut {\n        match self {\n            Writer::Plain(writer) => writer,\n            Writer::Gzip(writer) => writer\n                .into_inner()\n                .expect(\"BufWriter writer should not fail to finish\")\n                .finish()\n                .expect(\"gzip writer should not fail to finish\"),\n            Writer::Zlib(writer) => writer\n                .into_inner()\n                .expect(\"BufWriter writer should not fail to finish\")\n                .finish()\n                .expect(\"zlib writer should not fail to finish\"),\n            Writer::Zstd(writer) => writer\n                .finish()\n                .expect(\"zstd writer should not fail to finish\"),\n            Writer::Snappy(writer) => writer\n                .finish()\n                .expect(\"snappy writer should not fail to finish\"),\n        }\n        .into_inner()\n    }\n\n    pub fn finish(self) -> io::Result<BytesMut> {\n        let buf = match self {\n            Writer::Plain(writer) => writer,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/compressor.rs#L21-L57","documentation":"A panic assertion on `GzEncoder::finish()` in `Writer::into_inner` (compressor.rs). flate2's `finish` writes the gzip trailer into the inner in-memory writer, which cannot fail, so Vector asserts success. A panic indicates the in-memory write failed — an internal invariant violation (typically allocation failure growing the output BytesMut).","triggerScenarios":"Calling `Writer::into_inner()` with `Compression::Gzip` when `GzEncoder::finish` returns Err finalizing the stream into the BytesMut-backed writer.","commonSituations":"Rare; only plausible under memory pressure while finalizing a gzip payload for a sink request body.","solutions":["Ensure adequate memory headroom for the process.","Prefer the fallible `Writer::finish()` API which returns `io::Result` instead of asserting.","File a Vector bug if the panic recurs without memory pressure."],"exampleFix":"// before\n.finish().expect(\"gzip writer should not fail to finish\")\n// after\n.finish()?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match writer.into_inner() {\n    Ok(enc) => match enc.finish() {\n        Ok(enc2) => send(enc2.into_inner()),\n        Err(e) => log::warn!(\"gzip finish failed: {e}\"),\n    },\n    Err(e) => log::warn!(\"bufwriter flush failed: {e}\"),\n}","preventionTips":["Prefer propagating io::Result over .expect on flate2 finish calls.","Ensure memory headroom so gzip trailer writes cannot fail.","Cover gzip sink paths with integration tests under constrained memory."],"tags":["rust","compression","gzip","panic"],"backgroundTag":"internal-invariant-violation","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"}