Skip to content

in_forward: fix 100% CPU hang and connection teardown use-after-free [Backport to 4.2]#12053

Merged
cosmo0920 merged 4 commits into
4.2from
fix-12025-priority-queue-stale-event-4.2
Jul 7, 2026
Merged

in_forward: fix 100% CPU hang and connection teardown use-after-free [Backport to 4.2]#12053
cosmo0920 merged 4 commits into
4.2from
fix-12025-priority-queue-stale-event-4.2

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Partially backporting of #12044 due to lack of integration testing mechanism on 4.2 branch.
Plus, also backporting connections and downstream hardening from #11742 due to plugging lack of notification mechanism for a deletion of connections.


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.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c015736-5b5e-4958-ad13-41b84022484e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-12025-priority-queue-stale-event-4.2

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a499c837f4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/in_forward/fw_conn.c
edsiper added 4 commits July 6, 2026 13:56
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
A connection destroyed by the downstream timeout/pending-destroy
machinery can still have its event linked in the priority bucket queue
after mk_event_inject (only FLB_ENGINE_LOOP_MAX_ITER events are processed
per loop round). destroy_conn freed the connection unconditionally,
leaving a dangling _priority_head in the bucket queue.

On the next loop iteration flb_bucket_queue_pop_min dereferenced the
freed node (use-after-free), and the stale self-referential linkage made
flb_event_load_bucket_queue_event skip the event forever, so a socket in
CLOSE_WAIT kept waking epoll while its handler was never dispatched,
spinning the input thread at 100% CPU.

Mirror the guard already used by upstream destroy_conn: keep the
connection in the destroy_queue until its event has drained from the
bucket queue, then free it on a later sweep.

Fixes #12025

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
The plugin kept a fw_conn wrapper in ctx->connections for every active
connection but never registered a drop notification callback. When the
engine destroyed the underlying connection on its own (e.g. an IO
timeout via prepare_destroy_conn), the wrapper was left pointing at a
freed connection. The next fw_conn_del_all (backpressure pause or
shutdown) then dereferenced it, causing a use-after-free crash.

Register a drop_notification_callback that detaches and frees the
wrapper when the engine reclaims the connection, mirroring the
http_server pattern. Split the wrapper cleanup (fw_conn_release) from
the downstream release so fw_conn_del and the drop path don't
double-release, and guard fw_conn_event against a wrapper already
dropped by an injected event that fires after teardown.

Fixes #12025

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@cosmo0920 cosmo0920 force-pushed the fix-12025-priority-queue-stale-event-4.2 branch from a499c83 to 9ca5886 Compare July 6, 2026 05:30
@cosmo0920 cosmo0920 added this to the v4.2.7 milestone Jul 7, 2026
@cosmo0920 cosmo0920 merged commit 8bd89b5 into 4.2 Jul 7, 2026
53 of 55 checks passed
@cosmo0920 cosmo0920 deleted the fix-12025-priority-queue-stale-event-4.2 branch July 7, 2026 02:54
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.

2 participants