{"record":{"id":"a82ee7d414718e5c","repo":"vectordotdev/vector","slug":"bufwriter-writer-should-not-fail-to-finish","errorCode":null,"errorMessage":"BufWriter writer should not fail to finish","messagePattern":"BufWriter writer should not fail to finish","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/compressor.rs","lineNumber":37,"sourceCode":"}\n\nimpl 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> {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/compressor.rs#L19-L55","documentation":"A panic assertion on `BufWriter::into_inner()` for the gzip arm of `Writer::into_inner` in `src/sinks/util/compressor.rs`. `BufWriter::into_inner` returns `io::Result` because flushing buffered bytes can fail, but the flushed bytes go into an in-memory encoder writing to `BytesMut`, so Vector treats it as infallible. A panic here would indicate the buffered flush failed — an internal invariant violation such as allocation failure.","triggerScenarios":"Calling `Compressor::into_inner()`/`Writer::into_inner()` with `Compression::Gzip` when `BufWriter::into_inner` fails to flush its 4 KiB input buffer into the GzEncoder.","commonSituations":"Rare; practically only under memory exhaustion when the flush allocation fails while finalizing a gzip-compressed sink payload.","solutions":["Increase process/container memory limits so buffer flushes can allocate.","Use the fallible `Writer::finish()` path instead of the panicking `into_inner()` if adapting this code upstream.","Report as a Vector invariant violation if it occurs under normal memory conditions."],"exampleFix":"// before\nwriter.into_inner().expect(\"BufWriter writer should not fail to finish\")\n// after\nlet encoder = writer.into_inner()?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Prefer the fallible API over the panicking into_inner:\nlet bytes: io::Result<BytesMut> = writer.finish(); // propagates Err instead of panicking\nmatch bytes {\n    Ok(buf) => send(buf),\n    Err(e) => log::warn!(\"compressor finish failed: {e}\"),\n}","preventionTips":["Use `Writer::finish()` (io::Result) instead of the asserting `into_inner()` when building on this code.","Keep BufWriter flush paths under normal memory conditions.","Add allocation-failure monitoring for sink processes."],"tags":["rust","compression","gzip","bufwriter","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"}