{"record":{"id":"c078e8ef2e2387f0","repo":"vectordotdev/vector","slug":"zstd-writer-should-not-fail-to-finish","errorCode":null,"errorMessage":"zstd writer should not fail to finish","messagePattern":"zstd writer should not fail to finish","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/compressor.rs","lineNumber":47,"sourceCode":"        }\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,\n            Writer::Gzip(writer) => writer.into_inner()?.finish()?,\n            Writer::Zlib(writer) => writer.into_inner()?.finish()?,\n            Writer::Zstd(writer) => writer.finish()?,\n            Writer::Snappy(writer) => writer.finish()?,\n        }\n        .into_inner();\n\n        Ok(buf)","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/compressor.rs#L29-L65","documentation":"A panic assertion on `ZstdEncoder::finish()` in `Writer::into_inner` (compressor.rs). Finishing a zstd encoder writes the final frame into an in-memory `BytesMut` writer, which cannot fail, so Vector treats it as infallible. A panic here indicates the finalization write failed (e.g. allocation failure) — an internal invariant violation rather than a condition callers can handle.","triggerScenarios":"Calling `Writer::into_inner()` with `Compression::Zstd` when `ZstdEncoder::finish` returns Err writing the terminating bytes of the zstd frame.","commonSituations":"Rare; only plausible under severe memory exhaustion while finalizing a zstd-compressed payload before sending it to a sink.","solutions":["Increase memory available to the Vector process/container.","Temporarily switch sink compression to a different codec while investigating.","Report the panic to Vector maintainers as an invariant violation if it recurs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let buf = writer.finish()?; // fallible variant returns io::Result<BytesMut>\nmatch buf {\n    Ok(bytes) => send(bytes),\n    Err(e) => log::warn!(\"zstd finish failed: {e}\"),\n}","preventionTips":["Use the fallible `Writer::finish()` API instead of the asserting `into_inner()`.","Keep zstd compression levels moderate to bound finalization memory use.","Provision memory headroom proportional to batch.max_bytes for zstd sinks."],"tags":["rust","compression","zstd","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"}