Skip to content

plugins: fix dry-run segmentation faults#12114

Open
patrick-stephens wants to merge 3 commits into
masterfrom
fixup_azure_blob
Open

plugins: fix dry-run segmentation faults#12114
patrick-stephens wants to merge 3 commits into
masterfrom
fixup_azure_blob

Conversation

@patrick-stephens

@patrick-stephens patrick-stephens commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Various plugins trigger segmentation faults on exit due to missing null checks similar to #11800. This was detected during documentation checks of examples configurations: fluent/fluent-bit-docs#2627

Resolves #12113.


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
    Using the official documented configuration for each of these plugins:
  • Debug log output from testing the change
    Each reports configuration test is successful now when using the container image.

  • 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 shutdown reliability for Azure Blob, Kafka REST, and NATS outputs.
    • Prevented errors caused by missing or uninitialized output contexts during cleanup.
    • Ensured resources are released safely when valid shutdown contexts are available.

Signed-off-by: Patrick Stephens <pat@telemetryforge.io>
Signed-off-by: Patrick Stephens <pat@telemetryforge.io>
Signed-off-by: Patrick Stephens <pat@telemetryforge.io>
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Output teardown functions for Azure Blob, Kafka REST, and NATS now guard against NULL contexts before performing cleanup, preventing invalid dereferences during dry-run shutdown.

Changes

Output teardown safety

Layer / File(s) Summary
Guard output teardown paths
plugins/out_azure_blob/azure_blob.c, plugins/out_kafka_rest/kafka.c, plugins/out_kafka_rest/kafka_conf.c, plugins/out_nats/nats.c
Exit callbacks and Kafka REST configuration destruction return early when their contexts are NULL.

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

Possibly related PRs

Suggested reviewers: edsiper

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing dry-run crash handling in output plugins.
Linked Issues check ✅ Passed The changes add null checks in azure_blob, nats, and kafka-rest exit paths, matching the segfault fix requested in #12113.
Out of Scope Changes check ✅ Passed The patch stays focused on null-check fixes in the three affected plugins and does not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fixup_azure_blob

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.

@patrick-stephens

Copy link
Copy Markdown
Contributor Author

@cosmo0920 probably need to add some dry run tests for these plugins but is there a way we can add dry run tests to every plugin easily?

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

🧹 Nitpick comments (1)
plugins/out_azure_blob/azure_blob.c (1)

2433-2435: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the required brace style for the new guards.

The four added if statements place the opening brace on the same line. Reformat them with the opening brace on the next line to match the repository’s C/C++ convention:

  • plugins/out_azure_blob/azure_blob.c Lines 2433-2435
  • plugins/out_kafka_rest/kafka.c Lines 341-343
  • plugins/out_kafka_rest/kafka_conf.c Lines 200-202
  • plugins/out_nats/nats.c Lines 234-236

As per coding guidelines, C/C++ control-statement opening braces must be placed on the next line.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob.c` around lines 2433 - 2435, Reformat the
four newly added guard statements so each opening brace is on the following
line, matching the repository’s C/C++ brace convention: apply this change to
plugins/out_azure_blob/azure_blob.c lines 2433-2435,
plugins/out_kafka_rest/kafka.c lines 341-343,
plugins/out_kafka_rest/kafka_conf.c lines 200-202, and plugins/out_nats/nats.c
lines 234-236. Preserve the existing guard logic and returns.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugins/out_azure_blob/azure_blob.c`:
- Around line 2433-2435: Reformat the four newly added guard statements so each
opening brace is on the following line, matching the repository’s C/C++ brace
convention: apply this change to plugins/out_azure_blob/azure_blob.c lines
2433-2435, plugins/out_kafka_rest/kafka.c lines 341-343,
plugins/out_kafka_rest/kafka_conf.c lines 200-202, and plugins/out_nats/nats.c
lines 234-236. Preserve the existing guard logic and returns.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9ffd8a0-5d6f-45f0-80d9-adb134182655

📥 Commits

Reviewing files that changed from the base of the PR and between fd5ea1f and ab972aa.

📒 Files selected for processing (4)
  • plugins/out_azure_blob/azure_blob.c
  • plugins/out_kafka_rest/kafka.c
  • plugins/out_kafka_rest/kafka_conf.c
  • plugins/out_nats/nats.c

@cosmo0920

cosmo0920 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@cosmo0920 probably need to add some dry run tests for these plugins but is there a way we can add dry run tests to every plugin easily?

For output tests, we can implement it like as below:

For windows testing:

dry_run_outputs.ps1

. "$PSScriptRoot/common.ps1"

try {
    Assert-RuntimeEnvironment

    $schemaOutput = & $env:FLB_BIN -J 2>&1 | Out-String
    $schemaExitCode = $LASTEXITCODE
    if ($schemaExitCode -ne 0) {
        throw "Could not list compiled plugins (exit code $schemaExitCode)"
    }

    $schema = $schemaOutput | ConvertFrom-Json
    $plugins = @($schema.outputs | ForEach-Object { $_.name })
    if ($plugins.Count -eq 0) {
        throw "No compiled output plugins were reported"
    }

    $failures = [System.Collections.Generic.List[string]]::new()

    foreach ($plugin in $plugins) {
        $output = & $env:FLB_BIN --dry-run -i dummy -o $plugin 2>&1 |
            Out-String
        $exitCode = $LASTEXITCODE
        $hasSuccessMarker = $output.Contains(
            "configuration test is successful")

        if ($exitCode -eq 0 -and $hasSuccessMarker) {
            Write-Host "PASS: $plugin"
        }
        else {
            Write-Host "FAIL: $plugin (exit code $exitCode)"
            Write-Host $output
            $failures.Add($plugin)
        }
    }

    if ($failures.Count -ne 0) {
        throw ("Dry-run failed for output plugin(s): {0}" -f
            ($failures -join ", "))
    }

    Write-Host "Dry-run passed for all $($plugins.Count) compiled output plugins"
    exit 0
}
catch {
    Write-Host "ERROR: $($_.Exception.Message)"
    exit 1
}

For unix-shell enabled environments:

dry_run_outputs.sh

#!/bin/sh

FLB_ROOT=${FLB_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)}
FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit}

SCHEMA_OUTPUT=$("$FLB_BIN" -J 2>&1)
SCHEMA_EXIT_CODE=$?

if [ "$SCHEMA_EXIT_CODE" -ne 0 ]; then
    echo "Could not list compiled plugins (exit code $SCHEMA_EXIT_CODE)"
    echo "$SCHEMA_OUTPUT"
    exit 1
fi

PLUGINS=$(printf '%s\n' "$SCHEMA_OUTPUT" |
    grep -o '"type":"output","name":"[^"]*"' |
    sed 's/^"type":"output","name":"//; s/"$//')

if [ -z "$PLUGINS" ]; then
    echo "No compiled output plugins were reported"
    exit 1
fi

FAILURES=""
FAILURE_COUNT=0
PLUGIN_COUNT=0

for PLUGIN in $PLUGINS; do
    PLUGIN_COUNT=$((PLUGIN_COUNT + 1))
    OUTPUT=$("$FLB_BIN" --dry-run -i dummy -o "$PLUGIN" 2>&1)
    EXIT_CODE=$?

    if [ "$EXIT_CODE" -eq 0 ] &&
       printf '%s\n' "$OUTPUT" | grep -Fq "configuration test is successful"; then
        echo "PASS: $PLUGIN"
    else
        echo "FAIL: $PLUGIN (exit code $EXIT_CODE)"
        echo "$OUTPUT"
        FAILURES="$FAILURES $PLUGIN"
        FAILURE_COUNT=$((FAILURE_COUNT + 1))
    fi
done

if [ "$FAILURE_COUNT" -ne 0 ]; then
    echo "Dry-run failed for output plugin(s):$FAILURES"
    exit 1
fi

echo "Dry-run passed for all $PLUGIN_COUNT compiled output plugins"
exit 0

And adding the below lines are needed to enabled these test cases:

diff --git a/tests/runtime_shell/CMakeLists.txt b/tests/runtime_shell/CMakeLists.txt
index 34cacd1c5..f79c82bed 100644
--- a/tests/runtime_shell/CMakeLists.txt
+++ b/tests/runtime_shell/CMakeLists.txt
@@ -11,6 +11,7 @@ if(WIN32)

   if(POWERSHELL_EXECUTABLE)
     set(UNIT_TESTS_PS
+      dry_run_outputs.ps1
       in_dummy_expect.ps1
       in_tail_expect.ps1
       in_syslog_tcp_plaintext_expect.ps1
@@ -73,6 +74,7 @@ else()
   set(UNIT_TESTS_SH
     custom_calyptia.sh
     dry_run_invalid_property.sh
+    dry_run_outputs.sh
     in_dummy_expect.sh
     in_tail_expect.sh
     in_http_tls_expect.sh

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dry-run segmentation faults in azure_blob, nats & kafka-rest output plugins

2 participants