vectordotdev/vector · error

BufWriter writer should not fail to finish

Error message

BufWriter writer should not fail to finish

What it means

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.

Solutions

  1. Increase process/container memory limits so buffer flushes can allocate.
  2. Use the fallible `Writer::finish()` path instead of the panicking `into_inner()` if adapting this code upstream.
  3. Report as a Vector invariant violation if it occurs under normal memory conditions.

Example fix

// before
writer.into_inner().expect("BufWriter writer should not fail to finish")
// after
let encoder = writer.into_inner()?;
Defensive patterns

Strategy: try-catch

Try / catch

// Prefer the fallible API over the panicking into_inner:
let bytes: io::Result<BytesMut> = writer.finish(); // propagates Err instead of panicking
match bytes {
    Ok(buf) => send(buf),
    Err(e) => log::warn!("compressor finish failed: {e}"),
}

Prevention

When it happens

Trigger: 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.

Common situations: Rare; practically only under memory exhaustion when the flush allocation fails while finalizing a gzip-compressed sink payload.

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


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/a82ee7d414718e5c. Report an issue: GitHub.

Appendix: source

Thrown at src/sinks/util/compressor.rs:37

}

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> {

View on GitHub (pinned to bdb87aeaa4)