Skip to content

Conversation

@edsiper
Copy link
Member

@edsiper edsiper commented Nov 8, 2025

When a retry or error happens, if AWS auth is being used we are leaking the signature buffer, this PR corrects that.


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 resource cleanup in the OpenSearch plugin to prevent potential memory leaks during error and retry scenarios, enhancing stability and reliability of OpenSearch operations.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@coderabbitai
Copy link

coderabbitai bot commented Nov 8, 2025

Walkthrough

Enhanced AWS signature resource cleanup in the cb_opensearch_flush function across all error and retry paths. Added explicit destruction of the signature resource and null initialization on HTTP operation failures, status errors, and retry branches to prevent memory leaks.

Changes

Cohort / File(s) Summary
AWS Signature Resource Cleanup
plugins/out_opensearch/opensearch.c
Added explicit destruction and nullification of signature resource on HTTP do failure path, HTTP status error path (non-200/201), and various retry branches to prevent memory leaks in cb_opensearch_flush function

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify all error and retry paths in cb_opensearch_flush have proper signature cleanup and nullification
  • Ensure cleanup occurs before any branching to retry logic
  • Check that cleanup pattern is consistent across all affected paths

Poem

🐰 A signature that danced too free,
Now gets destroyed when errors be,
Through retry paths both old and new,
Memory leaks—we bid adieu! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing a memory leak by releasing the AWS signature resource when retries or errors occur in the OpenSearch output plugin.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch out_opensearch_signature

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.

@edsiper edsiper added this to the Fluent Bit v4.2 milestone Nov 8, 2025
Copy link

@coderabbitai coderabbitai bot left a 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)
plugins/out_opensearch/opensearch.c (1)

1044-1047: LGTM! Correctly fixes signature leak on empty response payload.

The signature cleanup when the response payload is empty or missing properly prevents the memory leak on this edge case path.

Optional: Consider extracting signature cleanup into a helper.

The signature cleanup pattern is repeated in 4 locations (lines 977-980, 995-998, 1032-1035, 1044-1047). While the current approach is correct and clear, you could optionally extract this into a small inline helper function to reduce duplication:

static inline void cleanup_signature(flb_sds_t *sig) {
    if (*sig) {
        flb_sds_destroy(*sig);
        *sig = NULL;
    }
}

Then call cleanup_signature(&signature); at each location. However, this is purely optional—the current explicit cleanup is perfectly acceptable for a targeted bug fix.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4c158d and 11f53c2.

📒 Files selected for processing (1)
  • plugins/out_opensearch/opensearch.c (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/out_opensearch/opensearch.c (1)
src/flb_sds.c (1)
  • flb_sds_destroy (389-399)
⏰ 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 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: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-compile-without-cxx (3.31.6)
  • 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, 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-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: 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_SIMD=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_THREAD=On, 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_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=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_COVERAGE=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 (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • 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_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • 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_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (3)
plugins/out_opensearch/opensearch.c (3)

977-980: LGTM! Correctly fixes signature leak on HTTP failure.

The signature cleanup on the flb_http_do failure path properly prevents the memory leak when AWS authentication is enabled and the HTTP operation fails.


995-998: LGTM! Correctly fixes signature leak on HTTP status error.

The signature cleanup when HTTP status is neither 200 nor 201 properly prevents the memory leak on error response paths.


1032-1035: LGTM! Correctly fixes signature leak on OpenSearch error response.

The signature cleanup after detecting errors in the OpenSearch response payload properly prevents the memory leak when the error check indicates issues with the bulk operation.

@edsiper edsiper merged commit c26a2d1 into master Nov 9, 2025
68 checks passed
@edsiper edsiper deleted the out_opensearch_signature branch November 9, 2025 12:26
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