vectordotdev/vector · error
Zstd encoder should not fail on init.
Error message
Zstd encoder should not fail on init.
What it means
This panic fires when constructing a `ZstdEncoder` in `Compressor::from` fails. Per the zstd crate, encoder initialization only fails on an invalid compression level or allocation failure; Vector guarantees the configured level is in the valid 1-22 range, so failure means the invariant is broken.
Solutions
- Report as a bug; this indicates an internal invariant about level validity was broken.
- Verify the sink `compression: zstd` level configuration is a valid level (default/1-22).
- Check host memory availability if this occurs at startup under heavy load.
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the configured compression level is valid before building the compressor. assert!((1..=22).contains(&level), "zstd level must be 1-22");
Prevention
- Use default compression levels unless you have validated the range.
- Watch for OOM conditions at sink startup on memory-constrained hosts.
- Keep the zstd crate and Vector versions in sync with upstream releases.
When it happens
Trigger: Building a compressor with `Compression::Zstd(level)` where the mapped zstd level is outside the encoder's accepted range, or the allocator cannot provide memory for the encoder context.
Common situations: Essentially unreachable via normal config since Vector validates/normalizes zstd levels; could only appear under extreme memory pressure (OOM conditions) at sink construction.
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
- Zstd encoder should not fail on init.
- zstd writer should not fail to finish
- BufWriter writer should not fail to finish
- gzip writer should not fail to finish
- max_zstd_window_log already set
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/9b2b207b4a7b006f.
Report an issue: GitHub.
Appendix: source
Thrown at src/sinks/util/compressor.rs:90
match compression {
Compression::None => Writer::Plain(writer),
// Buffering writes to the underlying Encoder writer
// to avoid Vec-trashing and expensive memset syscalls.
// https://github.com/rust-lang/flate2-rs/issues/395#issuecomment-1975088152
Compression::Gzip(level) => Writer::Gzip(BufWriter::with_capacity(
GZIP_INPUT_BUFFER_CAPACITY,
GzEncoder::new(writer, level.as_flate2()),
)),
// Buffering writes to the underlying Encoder writer
// to avoid Vec-trashing and expensive memset syscalls.
// https://github.com/rust-lang/flate2-rs/issues/395#issuecomment-1975088152
Compression::Zlib(level) => Writer::Zlib(BufWriter::with_capacity(
ZLIB_INPUT_BUFFER_CAPACITY,
ZlibEncoder::new(writer, level.as_flate2()),
)),
Compression::Zstd(level) => {
let encoder = ZstdEncoder::new(writer, level.into())
.expect("Zstd encoder should not fail on init.");
Writer::Zstd(encoder)
}
Compression::Snappy => Writer::Snappy(SnappyEncoder::new(writer)),
}
}
}
impl io::Write for Writer {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
#[allow(clippy::disallowed_methods)] // Caller handles the result of `write`.
match self {
Writer::Plain(inner_buf) => inner_buf.write(buf),
Writer::Gzip(writer) => writer.write(buf),
Writer::Zlib(writer) => writer.write(buf),
Writer::Zstd(writer) => writer.write(buf),
Writer::Snappy(writer) => writer.write(buf),
}
}View on GitHub (pinned to bdb87aeaa4)