-
Notifications
You must be signed in to change notification settings - Fork 1.8k
out_azure_kusto: fix SIGSEGV in nested mk_list_foreach_safe loops #11212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
out_azure_kusto: fix SIGSEGV in nested mk_list_foreach_safe loops #11212
Conversation
WalkthroughUpdated the Azure Kusto output plugin to use a dedicated inner safety iterator variable; added a new runtime test that verifies buffering/backlog processing with two-phase Fluent Bit runs and accompanying cleanup helpers. Changes
Sequence Diagram(s)%%{init: {"themeVariables": {"primaryColor":"#2b8cbe","tertiaryColor":"#a6bddb","lineColor":"#1f3b57"}}}%%
sequenceDiagram
participant Test as Test harness
participant FB1 as Fluent Bit (run 1)
participant Disk as Buffer dir (disk)
participant FB2 as Fluent Bit (run 2)
participant Kusto as Azure Kusto output
Note over Test,FB1: Phase 1 — buffering enabled
Test->>FB1: start with buffer_dir configured
FB1->>Disk: write buffered records to disk
FB1-->>Test: exit after flush to disk
Note over Test,FB2: Phase 2 — restart to process backlog
Test->>FB2: start pointing to same buffer_dir
FB2->>Disk: read backlog files
FB2->>Kusto: deliver buffered records
FB2-->>Test: report success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🔇 Additional comments (5)
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. Comment |
8d08559 to
55130bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/runtime/out_azure_kusto.c (1)
217-286: Consider adding test directory cleanup for reliability.The test uses a hardcoded buffer directory
/tmp/fluent-bit-kusto-test/without cleanup. Leftover files from previous runs could cause flaky behavior or mask test failures.Consider adding cleanup before and after the test:
void flb_test_azure_kusto_buffering_backlog(void) { int i; int ret; int bytes; char sample[] = "{\"k\":\"v\"}"; size_t sample_size = sizeof(sample) - 1; flb_ctx_t *ctx; int in_ffd; int out_ffd; + + /* Clean up any leftover files from previous runs */ + system("rm -rf /tmp/fluent-bit-kusto-test/"); /* First run: enable buffering and write data to disk */And at the end:
flb_stop(ctx); flb_destroy(ctx); + + /* Clean up test directory */ + system("rm -rf /tmp/fluent-bit-kusto-test/"); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/out_azure_kusto/azure_kusto.c(2 hunks)tests/runtime/out_azure_kusto.c(3 hunks)
🔇 Additional comments (2)
plugins/out_azure_kusto/azure_kusto.c (1)
410-431: LGTM! Correct fix for the nested loop iterator collision.The introduction of
f_tmpas a dedicated temporary iterator for the innermk_list_foreach_safeloop properly resolves the SIGSEGV. Previously, both loops sharedtmp, causing the inner loop to overwrite the outer loop's saved "next" pointer, corrupting iteration state upon returning to the outer loop.tests/runtime/out_azure_kusto.c (1)
33-33: LGTM! Forward declaration and test list entry properly added.Also applies to: 42-42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/runtime/out_azure_kusto.c (1)
244-245: Consider test isolation and cleanup for the buffer directory.The hardcoded path
/tmp/fluent-bit-kusto-test/may cause issues with parallel test runs or leave stale files between runs. Consider:
- Using a unique temp directory (e.g., with
mkdtemppattern or PID suffix).- Cleaning up the buffer directory at test start and/or end.
For a regression test focused on preventing SIGSEGV, this is a minor concern, but cleanup would prevent accumulation of test artifacts.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/out_azure_kusto/azure_kusto.c(2 hunks)tests/runtime/out_azure_kusto.c(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- plugins/out_azure_kusto/azure_kusto.c
🧰 Additional context used
🧬 Code graph analysis (1)
tests/runtime/out_azure_kusto.c (1)
src/flb_lib.c (10)
flb_stop(1011-1055)flb_destroy(228-263)flb_create(143-225)flb_service_set(652-678)flb_input(266-276)flb_input_set(305-335)flb_output(279-289)flb_output_set(520-551)flb_start(983-994)flb_lib_push(843-870)
🔇 Additional comments (2)
tests/runtime/out_azure_kusto.c (2)
33-33: LGTM!The function declaration and TEST_LIST registration follow the existing patterns in this file.
Also applies to: 42-42
260-285: Regression test structure looks correct for its purpose.The two-phase approach (write buffered data, restart to process backlog) correctly exercises the
ingest_all_chunkscode path where the nested loop SIGSEGV occurred. If the test completes without crashing, the fix is validated.For enhanced verification, you could optionally add a comment clarifying that the test's success criterion is "no crash" rather than output validation.
55130bb to
ea67b3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/runtime/out_azure_kusto.c (1)
280-283: Consider adding verification that backlog processing occurred.While the test successfully exercises the buffering/backlog code path (its primary goal is crash prevention), it could be more robust by verifying that:
- Buffered data was actually loaded from disk
- Backlog processing completed
- The buffer directory state changed appropriately
This is optional since the test's main purpose—ensuring no SIGSEGV—is achieved if execution completes successfully.
Example verification (optional):
/* After line 283, verify buffer directory state or add logging check */ /* Note: This would require inspecting flb logs or buffer directory contents */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/out_azure_kusto/azure_kusto.c(2 hunks)tests/runtime/out_azure_kusto.c(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- plugins/out_azure_kusto/azure_kusto.c
🔇 Additional comments (1)
tests/runtime/out_azure_kusto.c (1)
33-33: LGTM!The function prototype and test list entry follow the established pattern in the file.
Also applies to: 42-42
The ingest_all_chunks() function had nested mk_list_foreach_safe loops that both used the same 'tmp' variable as the iterator. The macro stores the 'next' pointer in its second argument for safe iteration during list modification. When the inner loop overwrote 'tmp', it corrupted the outer loop's iteration state, causing undefined behavior and a SIGSEGV crash when processing buffered backlog data on startup. Fix: Add a dedicated 'f_tmp' variable for the inner loop to prevent iterator corruption. Also adds a regression test (buffering_backlog) that exercises the buffering/backlog restart code path to guard against future regressions. Signed-off-by: Yash Ananth <[email protected]> Signed-off-by: Yashwanth Anantharaju <[email protected]>
ea67b3e to
e9e2389
Compare
Disclaimer: Used copilot to investigate the crash we faced and took it's help to write this
Summary
Fixes a SIGSEGV crash in the Azure Kusto output plugin when processing buffered backlog data on startup.
Root Cause
The
ingest_all_chunks()function had nestedmk_list_foreach_safeloops that both used the sametmpvariable as the iterator:The
mk_list_foreach_safemacro stores the "next" pointer in its second argument for safe iteration during list modification. When the inner loop overwrotetmp, it corrupted the outer loop's iteration state, causing undefined behavior and eventually a SIGSEGV when the outer loop tried to continue iteration with a corrupted pointer.Crash Stack Trace (from production)
Fix
Add a dedicated
f_tmpvariable for the inner loop to prevent iterator corruption:Testing
flb_test_azure_kusto_buffering_backlogregression test that exercises the buffering/backlog restart code pathChanges
plugins/out_azure_kusto/azure_kusto.c: Addf_tmpiterator variable for inner loop (+2 lines, -1 line)tests/runtime/out_azure_kusto.c: Add buffering backlog regression test (+73 lines)Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.