Skip to content

bin: Handle CONT signal properly under leaks command - #11335

Merged
edsiper merged 2 commits into
masterfrom
cosmo0920-prevent-segv-under-leaks-handled-fluent-bit
Jan 5, 2026
Merged

bin: Handle CONT signal properly under leaks command#11335
edsiper merged 2 commits into
masterfrom
cosmo0920-prevent-segv-under-leaks-handled-fluent-bit

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

On macOS, we need to handle COND signal properly.
This is because under controling leaks command, it also sends COND signal after releasing its managing process(es).
To mitigate this, we need to use flag to mark for distinguish dump to be requested.
And we need to run it inside main loop.


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

Before applying this patch:

Process 33730 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.

Process:         fluent-bit [33730]
Path:            /Users/USER/*/fluent-bit
Load Address:    0x104290000
Identifier:      fluent-bit
Version:         0
Code Type:       ARM64
Platform:        macOS
Parent Process:  leaks [33729]
Target Type:     live task

Date/Time:       2026-01-05 16:46:47.791 +0900
Launch Time:     2026-01-05 16:46:15.802 +0900
OS Version:      macOS 26.0.1 (25A362)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         8320K
Physical footprint (peak):  9008K
Idle exit:                  untracked
----

leaks Report Version: 4.0, multi-line stacks
Process 33730: 1277 nodes malloced for 216 KB
Process 33730: 0 leaks for 0 total leaked bytes.

[2026/01/05 16:46:49] [engine] caught signal (SIGCONT)
[2026/01/05 16:46:49] Fluent Bit Dump

===== Input =====
[2026/01/05 16:46:49] [engine] caught signal (SIGSEGV)
ERROR: no debug info in Mach-O executable (-1)ERROR: no debug info in Mach-O executable (-1)ERROR: no debug info in Mach-O executable (-1)ERROR: no debug info in Mach-O executable (-1)ERROR: no debug info in Mach-O executable (-1)ERROR: no debug info in Mach-O executable (-1)(base) 

SEGV occurred due to free-ed memory region was requested to use.

After applying this patch:

rocess 37337 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.

Process:         fluent-bit [37337]
Path:            /Users/USER/*/fluent-bit
Load Address:    0x102f8c000
Identifier:      fluent-bit
Version:         0
Code Type:       ARM64
Platform:        macOS
Parent Process:  leaks [37336]
Target Type:     live task

Date/Time:       2026-01-05 16:54:59.581 +0900
Launch Time:     2026-01-05 16:54:52.693 +0900
OS Version:      macOS 26.0.1 (25A362)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         8416K
Physical footprint (peak):  9024K
Idle exit:                  untracked
----

leaks Report Version: 4.0, multi-line stacks
Process 37337: 1277 nodes malloced for 216 KB
Process 37337: 0 leaks for 0 total leaked bytes.

[2026/01/05 16:55:00] [engine] caught signal (SIGCONT)

Also, CONT signal is properly processed:

[2026/01/05 16:55:12] [engine] caught signal (SIGCONT)
[2026/01/05 16:55:12] Fluent Bit Dump

===== Input =====
opentelemetry.0 (opentelemetry)
│
├─ status
│  └─ overlimit     : no
│     ├─ mem size   : 0b (0 bytes)
│     └─ mem limit  : 0b (0 bytes)
│
├─ tasks
│  ├─ total tasks   : 0
│  ├─ new           : 0
│  ├─ running       : 0
│  └─ size          : 0b (0 bytes)
│
└─ chunks
   └─ total chunks  : 0
      ├─ up chunks  : 0
      ├─ down chunks: 0
      └─ busy chunks: 0
         ├─ size    : 0b (0 bytes)
         └─ size err: 0


===== Storage Layer =====
total chunks     : 0
├─ mem chunks    : 0
└─ fs chunks     : 0
   ├─ up         : 0
   └─ down       : 0
^C[2026/01/05 16:55:18] [engine] caught signal (SIGINT)
  • 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 signal handling by deferring dump requests to the main event loop rather than executing them inside the signal handler, increasing stability and safety.
    • Added a lightweight, signal-safe request mechanism so dump operations are performed asynchronously during normal processing.

✏️ Tip: You can customize this high-level summary in your review settings.

On macOS, we need to handle COND signal properly.
This is because under controling leaks command, it also sends COND
signal after releasing its managing process(es).
To mitigate this, we need to use flag to mark for distinguish dump to be
requested.
And we need to run it inside main loop.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@coderabbitai

coderabbitai Bot commented Jan 5, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Signal handling was changed to avoid calling flb_dump() directly inside the SIGCONT handler. A new global volatile flag dump_requested is set by the handler; the main event loop checks this flag and invokes flb_dump(ctx->config) when set.

Changes

Cohort / File(s) Summary
Signal handling / main loop
src/fluent-bit.c
Added volatile sig_atomic_t dump_requested global. SIGCONT handler now sets dump_requested = 1 instead of calling flb_dump() directly. Main loop checks the flag, resets it, and calls flb_dump(ctx->config) to perform the dump outside the signal handler.

Sequence Diagram(s)

sequenceDiagram
    participant OS as OS (signal)
    participant SH as SIGCONT handler
    participant ML as Main loop
    participant Dump as flb_dump()

    OS->>SH: deliver SIGCONT
    SH-->>SH: set dump_requested = 1
    Note right of ML: periodic/loop check
    ML->>ML: refresh context
    ML->>ML: if dump_requested == 1\ndump_requested = 0
    ML->>Dump: call flb_dump(ctx->config)
    Dump-->>ML: return
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

backport to v4.0.x, backport to v4.1.x

Suggested reviewers

  • edsiper
  • fujimotos

Poem

🐰 A signal hops in, a tiny thump—
I set a flag, then quietly jump.
The loop awakens, sees my cue,
Calls the dump and bids adieu. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: deferring SIGCONT signal handling to the main loop to prevent segmentation faults when macOS leaks command is running.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd00e1d and 2118a17.

📒 Files selected for processing (1)
  • src/fluent-bit.c
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-21T06:23:29.770Z
Learnt from: cosmo0920
Repo: fluent/fluent-bit PR: 11171
File: include/fluent-bit/flb_lib.h:52-53
Timestamp: 2025-11-21T06:23:29.770Z
Learning: In Fluent Bit core (fluent/fluent-bit repository), function descriptions/documentation are not required for newly added functions in header files.

Applied to files:

  • src/fluent-bit.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COMPILER_STRICT_POINTER_TYPES=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
🔇 Additional comments (3)
src/fluent-bit.c (3)

77-77: LGTM: Correct type for signal handler flag.

The use of volatile sig_atomic_t is the correct pattern for a flag that is written in a signal handler and read in the main loop. This ensures both atomicity and visibility across the signal handler boundary.


640-640: LGTM: Signal-safe implementation.

Moving from direct flb_dump(ctx->config) invocation to flag-setting correctly avoids calling non-async-signal-safe functions from the signal handler. This eliminates the SIGSEGV issue described in the PR.


1495-1499: LGTM: Properly deferred dump with NULL guards.

The main loop correctly processes the dump request with appropriate NULL checks for ctx and ctx->config. This addresses the concern raised in the previous review and ensures the dump operation runs in a safe context rather than in the signal handler.


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 and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Fix all issues with AI Agents 🤖
In @src/fluent-bit.c:
- Around line 1495-1498: The dump block uses ctx->config without ensuring ctx is
non-NULL; update the dump handling to check ctx and ctx->config before calling
flb_dump. Specifically, where dump_requested is handled, guard the flb_dump call
with a conditional like "if (dump_requested) { dump_requested = 0; if (ctx !=
NULL && ctx->config != NULL) flb_dump(ctx->config); }" so flb_dump is only
invoked when ctx and ctx->config are valid.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a981f66 and fd00e1d.

📒 Files selected for processing (1)
  • src/fluent-bit.c
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-21T06:23:29.770Z
Learnt from: cosmo0920
Repo: fluent/fluent-bit PR: 11171
File: include/fluent-bit/flb_lib.h:52-53
Timestamp: 2025-11-21T06:23:29.770Z
Learning: In Fluent Bit core (fluent/fluent-bit repository), function descriptions/documentation are not required for newly added functions in header files.

Applied to files:

  • src/fluent-bit.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COMPILER_STRICT_POINTER_TYPES=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (2)
src/fluent-bit.c (2)

77-77: LGTM! Correct type for signal-safe flag.

The use of volatile sig_atomic_t is the appropriate type for a flag that is modified by signal handlers and read by the main program, ensuring atomic and visible operations.


640-640: Excellent fix! Defers non-async-signal-safe operation to main loop.

Setting a flag instead of calling flb_dump directly in the signal handler is the correct approach. This avoids undefined behavior from calling non-async-signal-safe functions within a signal handler, which was the root cause of the SIGSEGV mentioned in the PR description.

Comment thread src/fluent-bit.c Outdated
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@edsiper

edsiper commented Jan 5, 2026

Copy link
Copy Markdown
Member

@codex review

@edsiper edsiper added this to the Fluent Bit v4.2.3 milestone Jan 5, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

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

@edsiper
edsiper merged commit ab34c0e into master Jan 5, 2026
58 of 60 checks passed
@edsiper
edsiper deleted the cosmo0920-prevent-segv-under-leaks-handled-fluent-bit branch January 5, 2026 19:43
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