Skip to content

Backport(v1.19): buffer: fix stage_size leak when a staged chunk is unstaged (#5440) - #5456

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5440
Jul 27, 2026
Merged

Backport(v1.19): buffer: fix stage_size leak when a staged chunk is unstaged (#5440)#5456
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5440

Conversation

@github-actions

Copy link
Copy Markdown

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

**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 Watson1978 added this to the v1.19.4 milestone Jul 27, 2026
@Watson1978
Watson1978 merged commit 131fba1 into v1.19 Jul 27, 2026
18 checks passed
@Watson1978
Watson1978 deleted the backport-to-v1.19/pr5440 branch July 27, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants