Skip to content

output: fail initialization when a worker thread cannot start - #12901

Open
estebanpavansarquis wants to merge 5 commits into
fluent:masterfrom
estebanpavansarquis:fix-output-worker-start-failure
Open

estebanpavansarquis wants to merge 5 commits into
fluent:masterfrom
estebanpavansarquis:fix-output-worker-start-failure

Conversation

@estebanpavansarquis

@estebanpavansarquis estebanpavansarquis commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

When an output worker thread fails to start, the error is ignored: the output is treated as ready and round-robin keeps assigning tasks to the worker that never runs, so those tasks never complete.

  • flb_tp_thread_start_all() stops at the first thread that fails to start and returns -1.
  • flb_output_thread_pool_start() returns that result.
  • flb_output_enable_multi_threading() releases the pool on start failure (joining the workers that started) and returns -1, so output initialization fails with could not start thread pool for '<name>' plugin. Releasing the pool there also covers the Go proxy path, where the instance is destroyed right after cb_init fails.
  • flb_worker_create() releases the worker log cache when the thread cannot be spawned. The new test reaches that path and LeakSanitizer reports it otherwise.
  • New internal test output_thread: worker_start_failure_is_reported wraps pthread_create() (Linux, GNU/Clang) to fail the second of two workers. It links fluent-bit-static, like flb-it-network_dns, because --wrap does not reach calls inside the shared library.

Fixes #12894


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
  • [N/A] 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.

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

Documentation

  • [N/A] 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.

Testing details

Configuration (same as #12894):

[SERVICE]
    Flush        1
    Grace        5
    Log_Level    debug

[INPUT]
    Name   dummy
    Tag    test
    Rate   1

[OUTPUT]
    Name    stdout
    Match   *
    Format  json_lines
    Workers 2

Run with docker run --pids-limit 4 ... so the second worker cannot be created. Startup now fails and the started worker is joined (exit code 255):

[Error] pthread_create: , errno=11 at /work/src/lib/monkey/mk_core/mk_utils.c:324
[info] [output:stdout:stdout.0] worker #0 started
[info] [output:stdout:stdout.0] thread worker #0 stopped
[error] [output] could not start thread pool for 'stdout.0' plugin
[error] [engine] output initialization failed

Without the PID limit both workers start and all tasks complete (service has stopped (0 pending tasks)).

Unit tests (Debian bookworm, aarch64):

  • flb-it-output_thread: the new test fails on master (ret == -1, output.tp == NULL and the started worker exit checks) and passes with this change, also with -DSANITIZE_ADDRESS=On.
  • ctest -L internal: 109/109 passed.

Summary by CodeRabbit

  • Bug Fixes
    • Output processing now reports failures when background workers cannot start, rather than continuing as if startup succeeded.
    • Failed worker startup now triggers cleanup, helping prevent incomplete multithreading setup and lingering resources.
    • Worker creation failures also clean up associated resources before returning an error.
  • Tests
    • Added coverage for failures during output worker startup and verified that cleanup occurs.

Signed-off-by: estebanpavansarquis <11792494+estebanpavansarquis@users.noreply.github.com>
Stop at the first thread that fails to start so callers can fail
instead of dispatching work to a thread that does not run.

Signed-off-by: estebanpavansarquis <11792494+estebanpavansarquis@users.noreply.github.com>
Signed-off-by: estebanpavansarquis <11792494+estebanpavansarquis@users.noreply.github.com>
Release the thread pool, joining the workers that started, so the
output is not left dispatching tasks to a worker that never runs.

Signed-off-by: estebanpavansarquis <11792494+estebanpavansarquis@users.noreply.github.com>
Wrap pthread_create() on Linux to fail the second worker and check that
enabling multi-threading fails and releases the pool.

Signed-off-by: estebanpavansarquis <11792494+estebanpavansarquis@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T18:21:16.607365Z e07e614 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 Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Output thread startup now propagates thread creation failures and cleans up the output pool. Worker-spawn failures also clean up the worker log cache. A conditional internal test injects pthread creation failure and checks the resulting error and cleanup.

Changes: Output worker startup

Layer / File(s) Summary
Propagate startup failures and clean up
src/flb_thread_pool.c, src/flb_output_thread.c, src/flb_worker.c, src/flb_output.c
Thread-start failures now propagate through output startup. The output pool is destroyed if startup fails, and worker log-cache state is destroyed if worker spawning fails.
Inject and verify thread creation failure
tests/internal/CMakeLists.txt, tests/internal/output_thread.c
On supported Linux GNU or Clang builds, the output-thread test target wraps pthread_create. The test injects a failure and checks the startup error, cleared output pool, and worker-exit callback.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Merge Risk: Minimal · up to e07e6

This change makes output initialization fail with a clear error when a worker thread cannot start, instead of leaving tasks assigned to a worker that is not running. No concrete merge-blocking risk was found, and an internal test covers the failure path.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "output: fail initialization when a worker thread cannot start" matches the main change. The PR makes output initialization fail when flb_tp_thread_start_all() reports a thread start failure…
Linked Issues check Passed [#12894] The objective is that a worker-start failure must not leave the output ready. The PR meets it through a chain of changes. flb_tp_thread_start_all() in src/flb_thread_pool.c now returns -1 a…
Out of Scope Changes check Passed All changed files relate to the #12894 objective. The changes in src/flb_thread_pool.c, src/flb_output_thread.c, and src/flb_output.c implement the start-failure propagation. The change in src/flb_wor…
Full details: Title check

Explanation

The title "output: fail initialization when a worker thread cannot start" matches the main change. The PR makes output initialization fail when flb_tp_thread_start_all() reports a thread start failure, and it propagates that error through flb_output_thread_pool_start() and flb_output_enable_multi_threading(). The title is specific, short, and free of file lists or vague wording. The supporting changes (worker log cache cleanup and the new pthread_create wrap test) are secondary details that the title does not need to cover.

Full details: Linked Issues check

Explanation

[#12894] The objective is that a worker-start failure must not leave the output ready. The PR meets it through a chain of changes. flb_tp_thread_start_all() in src/flb_thread_pool.c now returns -1 at the first flb_tp_thread_start() failure, instead of ignoring it. flb_output_thread_pool_start() returns that result (summary: src/flb_output_thread.c, previously always 0). flb_output_enable_multi_threading() in src/flb_output.c checks the result, calls flb_output_thread_pool_destroy(ins) to join started workers, and returns -1. Output initialization then fails with the plugin-named error could not start thread pool for '&lt;name&gt;' plugin, which satisfies the expected outcome. flb_worker_create() also releases the worker log cache on spawn failure. The new internal test output_thread: worker_start_failure_is_reported in tests/internal/output_thread.c injects a pthread_create() failure for the second of two workers and checks the -1 return, the cleared output.tp, and the worker-exit callback. The test is built against fluent-bit-static so --wrap applies. The author reports the test fails on master and passes with the change. I did not run the test. The diff inspection confirmed the flb_tp_thread_start_all() and flb_output_enable_multi_threading() changes.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the #12894 objective. The changes in src/flb_thread_pool.c, src/flb_output_thread.c, and src/flb_output.c implement the start-failure propagation. The change in src/flb_worker.c releases the worker log cache on the spawn-failure path that the new error handling exercises. The changes in tests/internal/CMakeLists.txt and tests/internal/output_thread.c add the test wrapper and its build wiring, which are supporting test changes. No unrelated functional change was found in the reviewed diffs. The summary lists no other files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d36510a0-50fb-4fbc-828d-21b70c84f5ca
Commits

Reviewing files that changed from the base of the PR and between 984519c and e07e614.

Files selected for processing: 6

  • src/flb_output.c
  • src/flb_output_thread.c
  • src/flb_thread_pool.c
  • src/flb_worker.c
  • tests/internal/CMakeLists.txt
  • tests/internal/output_thread.c

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

This branch has not been deployed

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

output: tasks are assigned to a worker thread that failed to start

1 participant