vectordotdev/vector · error
gzip writer should not fail to finish
Error message
gzip writer should not fail to finish
What it means
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).
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.
Example fix
// before
.finish().expect("gzip writer should not fail to finish")
// after
.finish()?; Defensive patterns
Strategy: try-catch
Try / catch
match writer.into_inner() {
Ok(enc) => match enc.finish() {
Ok(enc2) => send(enc2.into_inner()),
Err(e) => log::warn!("gzip finish failed: {e}"),
},
Err(e) => log::warn!("bufwriter flush failed: {e}"),
} Prevention
- 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.
When it happens
Trigger: Calling `Writer::into_inner()` with `Compression::Gzip` when `GzEncoder::finish` returns Err finalizing the stream into the BytesMut-backed writer.
Common situations: Rare; only plausible under memory pressure while finalizing a gzip payload for a sink request body.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- BufWriter writer should not fail to finish
- This can't fail because the inner writer is a Vec
- failed to finish encoder
- failed to write to encoder
- snappy writer should not fail to finish
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/fc524da70f8a980e.
Report an issue: GitHub.
Appendix: source
Thrown at src/sinks/util/compressor.rs:39
impl Writer {
pub fn get_ref(&self) -> &BytesMut {
match self {
Writer::Plain(inner) => inner.get_ref(),
Writer::Gzip(inner) => inner.get_ref().get_ref().get_ref(),
Writer::Zlib(inner) => inner.get_ref().get_ref().get_ref(),
Writer::Zstd(inner) => inner.get_ref().get_ref(),
Writer::Snappy(inner) => inner.get_ref().get_ref(),
}
}
pub fn into_inner(self) -> BytesMut {
match self {
Writer::Plain(writer) => writer,
Writer::Gzip(writer) => writer
.into_inner()
.expect("BufWriter writer should not fail to finish")
.finish()
.expect("gzip writer should not fail to finish"),
Writer::Zlib(writer) => writer
.into_inner()
.expect("BufWriter writer should not fail to finish")
.finish()
.expect("zlib writer should not fail to finish"),
Writer::Zstd(writer) => writer
.finish()
.expect("zstd writer should not fail to finish"),
Writer::Snappy(writer) => writer
.finish()
.expect("snappy writer should not fail to finish"),
}
.into_inner()
}
pub fn finish(self) -> io::Result<BytesMut> {
let buf = match self {
Writer::Plain(writer) => writer,View on GitHub (pinned to bdb87aeaa4)