{"record":{"id":"f8743c8d4510ad6a","repo":"vectordotdev/vector","slug":"this-can-t-fail-because-the-inner-writer-is-a-vec","errorCode":null,"errorMessage":"This can't fail because the inner writer is a Vec","messagePattern":"This can't fail because the inner writer is a Vec","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/buffer/mod.rs","lineNumber":140,"sourceCode":"                self.num_items >= self.settings.events || new_bytes >= self.settings.bytes,\n            )\n        }\n    }\n\n    fn is_empty(&self) -> bool {\n        self.is_empty()\n    }\n\n    fn fresh(&self) -> Self {\n        Self::new(self.settings, self.compression)\n    }\n\n    fn finish(self) -> Self::Output {\n        match self.inner {\n            Some(InnerBuffer::Plain(inner)) => inner.into_inner(),\n            Some(InnerBuffer::Gzip(inner)) => inner\n                .finish()\n                .expect(\"This can't fail because the inner writer is a Vec\")\n                .into_inner(),\n            Some(InnerBuffer::Zlib(inner)) => inner\n                .finish()\n                .expect(\"This can't fail because the inner writer is a Vec\")\n                .into_inner(),\n            Some(InnerBuffer::Zstd(inner)) => inner\n                .finish()\n                .expect(\"This can't fail because the inner writer is a Vec\")\n                .into_inner(),\n            Some(InnerBuffer::Snappy(inner)) => inner\n                .finish()\n                .expect(\"This can't fail because the inner writer is a Vec\")\n                .into_inner(),\n            None => BytesMut::new(),\n        }\n    }\n\n    fn num_items(&self) -> usize {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/buffer/mod.rs#L122-L158","documentation":"A panic assertion on `GzEncoder::finish()` inside `Buffer::finish()`. flate2's `finish()` returns `io::Result`, but the error variant only occurs when writing the compressed tail to the underlying writer fails. Here the underlying writer is an in-memory `Vec`-backed `BytesMut` writer, which cannot fail, so Vector asserts the invariant with `.expect`. This panic firing means the in-memory write failed — an internal invariant violation, not a user-facing error.","triggerScenarios":"Calling `Buffer::finish()` on a buffer initialized with `Compression::Gzip` when `GzEncoder::finish` returns Err — only possible if the inner `bytes::buf::Writer<BytesMut>` write fails, e.g. on memory allocation failure when growing the buffer.","commonSituations":"Under extreme memory pressure/OOM conditions when the buffer tries to grow while flushing the gzip footer; otherwise essentially never hit in normal operation regardless of sink configuration.","solutions":["Ensure the process has adequate memory headroom; this failure implies allocation failure, not data or config problems.","If it reproduces, check system memory limits (container cgroup limits) and increase them.","Report to Vector maintainers as an invariant violation if it fires without memory pressure."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Cannot be caught as an error; guard at the topology level:\nstd::panic::catch_unwind(|| buffer.finish())\n    .map_err(|_| ())\n    .unwrap_or_else(|_| fallback_plain_buffer()), // drop to uncompressed retry","preventionTips":["Ensure the host/container has memory headroom well above batch buffer sizes (batch.max_bytes).","Avoid extremely large batch settings that force big buffer growths at finish time.","Monitor container OOM/pressure metrics alongside Vector panics."],"tags":["rust","compression","gzip","panic","internal-invariant"],"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"}