Skip to content

out_s3: guard current_buffer_size subtraction against underflow - #12271

Open
univbyn-blip wants to merge 1 commit into
fluent:masterfrom
univbyn-blip:out_s3-buffer-size-underflow
Open

out_s3: guard current_buffer_size subtraction against underflow#12271
univbyn-blip wants to merge 1 commit into
fluent:masterfrom
univbyn-blip:out_s3-buffer-size-underflow

Conversation

@univbyn-blip

@univbyn-blip univbyn-blip commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #12270

s3_store_file_delete() subtracted s3_file->size from
ctx->current_buffer_size unconditionally. Buffer files recovered from
a previous run are not accounted into current_buffer_size at startup,
so deleting them after upload wraps the unsigned counter around to
~2^64. The store_dir_limit_size check then treats the buffer as
permanently full and rejects every new chunk ("Buffer is full",
"chunk cannot be retried"), causing data loss until restart.

Clamp the subtraction at zero, using the same pattern already applied
on the quarantine accounting path in s3.c.

Observed in production on 5.0.9 (Kubernetes DaemonSet, store_dir on a
hostPath volume surviving pod restarts):

[error] Buffer is full: current_buffer_size=18446744073709314048, new_data=4931, store_dir_limit_size=20000000000 bytes

18446744073709314048 == 2^64 - 237568 — the counter went "negative"
by exactly the size of the recovered-and-deleted files.


Testing

  • Example configuration file for the change
  • Debug log output from testing the change

Documentation

  • N/A — bug fix, no user-facing configuration change

Backporting

  • Backport to latest stable release.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where deleting certain files could cause storage usage tracking to become inaccurate.
    • Storage counters now remain at zero instead of dropping below zero when file sizes are unavailable.

Buffer files recovered from a previous run are not accounted into
current_buffer_size at startup, but s3_store_file_delete() subtracted
their size unconditionally. The unsigned counter wraps to ~2^64 and the
store_dir_limit_size check then rejects every new chunk (Buffer is
full / chunk cannot be retried), causing data loss until restart.

Clamp the subtraction at zero, matching the guard already used on the
quarantine accounting path.

Fixes fluent#12270

Signed-off-by: yena <univbyn@gmail.com>
@univbyn-blip
univbyn-blip requested a review from a team as a code owner August 12, 2026 08:14
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: deba4a3b-2f2a-42d3-a59f-ff143ece10f0

📥 Commits

Reviewing files that changed from the base of the PR and between ae51533 and 942e9ca.

📒 Files selected for processing (1)
  • plugins/out_s3/s3_store.c

📝 Walkthrough

Walkthrough

The S3 file deletion logic now prevents current_buffer_size from wrapping when deleting recovered files whose sizes were not included in startup accounting.

Changes

S3 buffer accounting

Layer / File(s) Summary
Guard file deletion accounting
plugins/out_s3/s3_store.c
s3_store_file_delete conditionally subtracts the deleted file size and clamps current_buffer_size to zero when necessary.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • fluent/fluent-bit#12266 — Modifies the same S3 buffer accounting path to prevent underflow during file deletion and startup accounting.

Suggested reviewers: cosmo0920, edsiper, leonardo-albertovich

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the out_s3 underflow fix, which is the primary change in the pull request.
Linked Issues check ✅ Passed The change clamps current_buffer_size and directly addresses issue #12270 by preventing underflow after deleting recovered buffer files.
Out of Scope Changes check ✅ Passed The pull request changes only the relevant out_s3 deletion accounting logic and contains no unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cosmo0920

Copy link
Copy Markdown
Contributor

This will be superseded by #12266.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants