compat: fix basename buffer to be thread-local on Windows#11553
compat: fix basename buffer to be thread-local on Windows#11553slab-msft wants to merge 1 commit intofluent:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA thread-local storage modifier ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
4b40170 to
6fff0e0
Compare
basename buffer thread-local on Windowsbasename buffer to be thread-local on Windows
|
This patch looks fine. |
Add __declspec(thread) to the static buffer in the Windows basename func to prevent data races in multi-threaded contexts, where concurrent calls could corrupt a shared static buffer Signed-off-by: slabbancz <slabbancz@microsoft.com>
6fff0e0 to
3904047
Compare
basename buffer to be thread-local on Windows
Add
__declspec(thread)to the static buffer in the Windowsbasenamefunc to prevent data races in multi-threaded contexts, where concurrent calls could corrupt a shared static buffer.__declspec(thread)
Issue: Windows basename() race condition causing false file rotation.
basename() in flb_compat.h returns a pointer to a global static char buf[_MAX_PATH].
When two tail inputs run their
worker threads concurrently call basename() via [tail_file.h]:
flb_tail_file_is_rotated() -> flb_tail_target_file_name_cmp()
Thread A sets base_b = basename(name_b) (pointer to shared buf), then Thread B
overwrites that buf before Thread A's _stricmp(base_a, base_b) reads it.
The corrupted comparison returns non-zero -> file falsely detected as rotated.
Symptom: repeated log entries on Windows:
[debug] inode=XXXXXXXXXX rotated: C:\logs\svc\svc_2.log => C:\logs\svc\svc_2.log
followed by the file being purged from DB and re-read from offset 0.
Example Config to reproduce:
Logs:
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:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
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