Skip to content

in_tail: Plug windows handle leak on exceptions - #12435

Open
cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-tail-windows-handle-leak
Open

cosmo0920 wants to merge 2 commits into
masterfrom
cosmo0920-tail-windows-handle-leak

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fixed in io.c line 41: failed descriptor allocation now closes the native handle. Both Windows open paths preserve errno during cleanup.

Added regression tests: tests/runtime/in_tail.c line 1636. Before the fix, 32 failed opens leaked 32 handles; afterward, both paths pass, including recovery when a descriptor becomes available.

Verification:

  • Windows build and three focused runtime tests: passed.
  • Focused integration tests: 2 passed, using:
    tests/integration/.venv/Scripts/python.exe -m pytest tests/integration/scenarios/in_tail/tests/test_in_tail_001.py -q -k 'discovers_new_files_from_head or windows_utf8_path_encoding'
    Used the rebuilt binary and a writable workspace temporary directory.
  • git diff --check: passed.
  • Valgrind/Leaks: not run; unavailable on Windows. Regression tests directly checked native handle counts.

Related to #12432.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows file-opening error handling so descriptor conversion failures consistently report the correct errno value.
    • Prevented cleanup operations from overwriting file-opening error details.
  • Tests

    • Added Windows coverage for file-descriptor exhaustion, including UTF-8 paths, handle cleanup, and recovery after releasing a descriptor.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920
cosmo0920 requested a review from edsiper as a code owner September 17, 2026 12:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-17T12:14:52.147276Z 9523e20 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5c0a9cd9-9fda-4014-a949-2e1bdb636b55

📥 Commits

Reviewing files that changed from the base of the PR and between e5e0bc7 and 9523e20.

📒 Files selected for processing (2)
  • plugins/in_tail/win32/io.c
  • tests/runtime/in_tail.c

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Windows open helpers now preserve errno when descriptor conversion fails. Windows runtime tests cover descriptor exhaustion, handle stability, and recovery for both helper functions.

Changes

Windows descriptor error handling

Layer / File(s) Summary
Preserve conversion errors
plugins/in_tail/win32/io.c
win32_open and win32_open_utf8 save and restore errno around CloseHandle when _open_osfhandle fails.
Validate descriptor exhaustion
tests/runtime/in_tail.c
Adds Windows tests that verify EMFILE, unchanged handle counts, descriptor recovery, and registration for both open helpers.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 9523e

The Windows descriptor-exhaustion handling is covered for both open paths, with no actionable current-head risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 main change: fixing a Windows handle leak in in_tail. It is concise and related to the pull request objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-tail-windows-handle-leak

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 cosmo0920 changed the title in_tail: Plug windows handle leak in_tail: Plug windows handle leak on exceptions Sep 17, 2026
@cosmo0920 cosmo0920 added this to the Fluent Bit v5.1.3 milestone Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant