Backport(v1.19): buffer: fix stage_size leak when a staged chunk is unstaged (#5440) - #5456
Merged
Conversation
**Which issue(s) this PR fixes**: Fixes #5439 **What this PR does / why we need it**: In `Buffer#write_step_by_step`, when a single record cannot be appended to an existing staged chunk without exceeding `chunk_limit_size`, the staged chunk is removed from `@stage`, marked unstaged and later enqueued via `enqueue_unstaged_chunk`. Unlike `enqueue_chunk`, `enqueue_unstaged_chunk` only adds to `@queue_size` and never subtracts from `@stage_size`, so the chunk's already-counted bytes remain in `@stage_size` forever. Over a long-lived process this makes `@stage_size` (and thus `fluentd_output_status_buffer_total_bytes` = `@stage_size` + `@queue_size`) drift upward, traffic-proportionally. Once it reaches `total_limit_size`, `storable?` returns `false` and every emit raises `Fluent::Plugin::Buffer::BufferOverflowError` even though the buffer is actually near-empty; input sources then reject incoming data. Subtract the chunk's original (already-counted) `bytesize` from `@stage_size` at the point of unstaging, so `total_queued_size` stays consistent with the real staged + queued bytes. **Docs Changes**: N/A **Release Note**: * buffer: fix `stage_byte_size` leak on staged→unstaged chunk demotion that could eventually raise spurious `BufferOverflowError`. Affects plugins implementing `#format`. Signed-off-by: Alexander Enrique Urieles Nieto <alexander@urieles.co> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Watson1978
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) this PR fixes:
Backport #5440
Fixes #5439
What this PR does / why we need it:
In
Buffer#write_step_by_step, when a single record cannot be appended to an existing staged chunk without exceedingchunk_limit_size, the staged chunk is removed from@stage, marked unstaged and later enqueued viaenqueue_unstaged_chunk. Unlikeenqueue_chunk,enqueue_unstaged_chunkonly adds to@queue_sizeand never subtracts from@stage_size, so the chunk's already-counted bytes remain in@stage_sizeforever.Over a long-lived process this makes
@stage_size(and thusfluentd_output_status_buffer_total_bytes=@stage_size+@queue_size) drift upward, traffic-proportionally. Once it reachestotal_limit_size,storable?returnsfalseand every emit raisesFluent::Plugin::Buffer::BufferOverflowErroreven though the buffer is actually near-empty; input sources then reject incoming data.Subtract the chunk's original (already-counted)
bytesizefrom@stage_sizeat the point of unstaging, sototal_queued_sizestays consistent with the real staged + queued bytes.Docs Changes:
N/A
Release Note:
stage_byte_sizeleak on staged→unstaged chunk demotion that couldeventually raise spurious
BufferOverflowError. Affects plugins implementing#format.