Skip to content

Move input coroutine management variables to TLS#11576

Open
runderwo wants to merge 4 commits intofluent:masterfrom
runderwo:master
Open

Move input coroutine management variables to TLS#11576
runderwo wants to merge 4 commits intofluent:masterfrom
runderwo:master

Conversation

@runderwo
Copy link
Copy Markdown
Contributor

@runderwo runderwo commented Mar 17, 2026

In c98a68e, coroutine state was moved to thread-local storage. However, the variables introduced to manage thread-local coroutine state were not themselves thread-local, which is a problem because flb_input_coro_collect() is not guarded against re-entrancy. This results in a race when multiple threads wake up from polling and run, because they then both read (e.g. in input_pre_cb_collect()) and overwrite (e.g. in flb_input_coro_collect()) the TLS key used to look up the stored coroutine state (libco_in_param_key), without synchronization.

There are almost certainly additional bugs here but this at least mitigates the race condition. The error handling logic in input_pre_cb_collect() was removed and replaced with an assert because the recovery path made no sense, and it's not clear there is in fact a sensible recovery path given the code structure.

Most likely this is related to #11488 and may be the root cause.


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

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

  • Refactor
    • Per-thread state is now initialized once in a thread-safe, deterministic setup to improve reliability of input handling.
  • Bug Fixes
    • Removed implicit lazy allocation of per-thread parameters; callers must ensure per-thread context is initialized, enabling earlier detection of uninitialized usage and more predictable teardown.

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