Skip to content

Conversation

ThomasDevoogdt
Copy link
Contributor

@ThomasDevoogdt ThomasDevoogdt commented Aug 31, 2025

/home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c: In function ‘net_connect_async’: /home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c:653:17: error: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  653 |             str = strerror_r(error, so_error_buf, sizeof(so_error_buf));
      |                 ^

This fix should work perfectly for:

  • glibc systems: Uses str = strerror_r(...) (GNU version)
  • musl systems: Uses ret = strerror_r(...); if (ret == 0) str = so_error_buf; (POSIX version)
  • Other libc implementations: Defaults to POSIX behavior

Fix is similar to janet-lang/janet@a5d6b22.


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.

Summary by CodeRabbit

  • New Features

    • None
  • Bug Fixes

    • More reliable and accurate error messages when a TCP connection fails.
    • Improved cross-platform behavior for error reporting on Linux (glibc) and other environments.
    • Prevents rare failures when retrieving error text during connection errors.
  • Refactor

    • Streamlined error-handling path for asynchronous network connections to improve robustness without changing external behavior.

/home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c: In function ‘net_connect_async’:
/home/thomas/br-test-pkg/bootlin-armv7-musl/build/fluent-bit-4.0.8/src/flb_network.c:653:17: error: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  653 |             str = strerror_r(error, so_error_buf, sizeof(so_error_buf));
      |                 ^

This fix should work perfectly for:

glibc systems: Uses str = strerror_r(...) (GNU version)
musl systems: Uses ret = strerror_r(...); if (ret == 0) str = so_error_buf; (POSIX version)
Other libc implementations: Defaults to POSIX behavior

Fix is similar to janet-lang/janet@a5d6b22.

Signed-off-by: Thomas Devoogdt <[email protected]>
Copy link

coderabbitai bot commented Aug 31, 2025

Walkthrough

The change updates error-string handling in net_connect_async when a TCP connection fails. It replaces POSIX/XOPEN conditionals with GLIBC-specific handling and distinct non-GLIBC logic, adjusting how strerror_r is invoked and how its result is used in the final log message. No public interfaces were changed.

Changes

Cohort / File(s) Summary
Network error handling (strerror_r paths)
src/flb_network.c
Refactors error-string derivation in net_connect_async failure path: introduces GLIBC guard using strerror_r’s char* return; non-GLIBC path checks int return, assigns buffer on success, otherwise logs via flb_errno() and returns -1. Final log uses computed error string.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Net as net_connect_async
  participant LibC as libc (strerror_r)
  participant Log as logger

  Caller->>Net: initiate TCP connect (async)
  Net-->>Caller: connection fails (SO\_ERROR set)

  rect rgb(240,248,255)
    Note over Net: Derive error string
    alt GLIBC build
      Net->>LibC: strerror_r(error, buf, sizeof(buf)) [returns char*]
      LibC-->>Net: str (pointer)
      Net->>Log: flb_warn("...: %s", str)
    else non-GLIBC build
      Net->>LibC: ret = strerror_r(error, buf, sizeof(buf)) [int]
      alt ret == 0
        Net->>Log: flb_warn("...: %s", buf)
      else ret != 0
        Net->>Log: flb_errno()
        Net-->>Caller: return -1
      end
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled on bytes by the socket’s den,
Tweaked strings for errors—now clearer than then.
GLIBC here, non-GLIBC there,
I hop through branches with careful care.
When connects fail and logs take flight,
My whiskers twitch—the message is right. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (3)
src/flb_network.c (3)

641-643: Tighten feature test to avoid false positives (e.g., uClibc)

Prefer guarding the GNU variant with both glibc and _GNU_SOURCE to avoid mis-detecting libcs that may define GLIBC compatibility macros but don’t provide the GNU strerror_r semantics.

Apply:

-#ifdef __GLIBC__
+#if defined(__GLIBC__) && defined(_GNU_SOURCE)
     str = strerror_r(error, so_error_buf, sizeof(so_error_buf));
 #else

Please verify builds on: glibc (Debian/Ubuntu), musl (Alpine), and, if relevant, uClibc/Bionic.


644-651: Make POSIX branch failure deterministic and preserve context in logs

On POSIX strerror_r failures, ret holds the failure code but errno may not be set; calling flb_errno() can log a stale errno and returns early, dropping the host/port context. Fall back to a formatted message instead and proceed to the flb_error() line.

Apply:

-    ret = strerror_r(error, so_error_buf, sizeof(so_error_buf));
-    if (ret == 0) {
-        str = so_error_buf;
-    }
-    else {
-        flb_errno();
-        return -1;
-    }
+    ret = strerror_r(error, so_error_buf, sizeof(so_error_buf));
+    if (ret == 0) {
+        str = so_error_buf;
+    }
+    else {
+        snprintf(so_error_buf, sizeof(so_error_buf),
+                 "strerror_r(%d) failed: %d", error, ret);
+        str = so_error_buf;
+    }

519-520: Minor: make error string pointer const

We don’t mutate the buffer; prefer const for clarity and to accept static strings returned by the GNU variant.

Change:

  • char *str;
    To:
  • const char *str;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1132279 and 8c094c4.

📒 Files selected for processing (1)
  • src/flb_network.c (1 hunks)
⏰ 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). (29)
  • 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: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 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_ARROW=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 (-DSANITIZE_ADDRESS=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=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_SANITIZE_MEMORY=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 (-DSANITIZE_ADDRESS=On, 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 (-DSANITIZE_UNDEFINED=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=Off, 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_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=On, 3.31.6, clang, clang++)
  • 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, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • 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
🔇 Additional comments (1)
src/flb_network.c (1)

641-643: LGTM: correct GNU strerror_r usage on glibc

Using the char*-returning GNU variant behind a glibc guard fixes the musl build error and is correct on glibc.

Copy link
Contributor

@cosmo0920 cosmo0920 left a comment

Choose a reason for hiding this comment

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

Looks attractive. Excellent work!

@cosmo0920 cosmo0920 added this to the Fluent Bit v4.1 milestone Sep 1, 2025
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.

3 participants