Skip to content

tests: core_routes: Handle limit of rlimit's soft limit#11592

Open
cosmo0920 wants to merge 1 commit intomasterfrom
cosmo0920-handle-small-rlim_cur
Open

tests: core_routes: Handle limit of rlimit's soft limit#11592
cosmo0920 wants to merge 1 commit intomasterfrom
cosmo0920-handle-small-rlim_cur

Conversation

@cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Mar 20, 2026

By default, macOS's soft limit of rlimit is up to 256. SO, just eating up 256 of output instances could cause too many open errors.

This is because the default value of masOS's ulimit -n is:

$ ulimit -n
256

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

  • Tests
    • Improved test reliability on macOS by adapting expected delivery counts to the system's file-descriptor limits at runtime; tests now scale with local resource limits, reducing false failures and making CI/local runs more robust and predictable.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c4cbd46-2680-4d84-a651-adc7cba8e9b9

📥 Commits

Reviewing files that changed from the base of the PR and between d411694 and 710b042.

📒 Files selected for processing (1)
  • tests/runtime/core_routes.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/runtime/core_routes.c

📝 Walkthrough

Walkthrough

The test tests/runtime/core_routes.c replaces a hardcoded loop bound (257) with a dynamic olimit; on macOS olimit is computed from getrlimit(RLIMIT_NOFILE). All loops and the final assertion now use olimit.

Changes

Cohort / File(s) Summary
macOS resource limit adaptation
tests/runtime/core_routes.c
Added macOS-only includes and an olimit variable; on macOS fetches RLIMIT_NOFILE via getrlimit and adjusts olimit. Replaced hardcoded 257 with olimit in output creation loop, delivery polling loop, and final assertion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • fujimotos
  • edsiper
  • koleini

Poem

🐰 I counted sockets, one by one,
No fixed number stopped my run,
On macOS I peek and see,
Limits guiding loops for me —
Hoppy tests pass merrily!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: adapting the core_routes test to handle macOS's rlimit soft limit constraints.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 cosmo0920-handle-small-rlim_cur

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.

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: 1

🧹 Nitpick comments (1)
tests/runtime/core_routes.c (1)

53-53: Extract 257 into a named constant to keep bounds synchronized.

257 is repeated across output_instances, olimit, loop bounds, and final assertion. A single constant reduces drift risk in future edits.

Proposed refactor
+ `#define` CORE_ROUTES_MAX_OUTPUTS 257
+
 void flb_test_basic_functionality_test(void)
 {
-    int                   output_instances[257];
+    int                   output_instances[CORE_ROUTES_MAX_OUTPUTS];
@@
-    size_t                olimit = 257;
+    size_t                olimit = CORE_ROUTES_MAX_OUTPUTS;
@@
-    if (rlim.rlim_cur < 257) {
+    if (rlim.rlim_cur < CORE_ROUTES_MAX_OUTPUTS) {
         olimit = rlim.rlim_cur/2.5;
     }

Also applies to: 77-77, 101-101, 108-108

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtime/core_routes.c` at line 53, Extract the repeated literal 257
into a named constant and replace all occurrences to keep bounds synchronized:
declare a constant (e.g., const size_t OUTPUT_LIMIT = 257) near the top of the
test and use OUTPUT_LIMIT in place of olimit's initialization, the
output_instances array size, any loop bounds that iterate to 257, and the final
assertion; update the variable olimit to be initialized from this constant or
remove olimit and use the constant directly so all references (output_instances,
olimit, the for/while loop conditions, and the assertion) consistently rely on
the single named symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/runtime/core_routes.c`:
- Around line 68-72: Guard the getrlimit call and ensure olimit is at least 1:
check the return value of getrlimit(RLIMIT_NOFILE, &rlim) and if it fails,
record the failure and return/abort the test early instead of proceeding to read
uninitialized rlim; when computing olimit from rlim.rlim_cur (used later with
delivery_counter) ensure you convert to an integer and enforce a minimum of 1
(e.g., olimit = max(1, (int)(rlim.rlim_cur / 2.5))) so the loop runs at least
once; update the code around getrlimit, rlim, olimit, and the test exit path to
avoid undefined reads and vacuous pass of TEST_CHECK(delivery_counter ==
olimit).

---

Nitpick comments:
In `@tests/runtime/core_routes.c`:
- Line 53: Extract the repeated literal 257 into a named constant and replace
all occurrences to keep bounds synchronized: declare a constant (e.g., const
size_t OUTPUT_LIMIT = 257) near the top of the test and use OUTPUT_LIMIT in
place of olimit's initialization, the output_instances array size, any loop
bounds that iterate to 257, and the final assertion; update the variable olimit
to be initialized from this constant or remove olimit and use the constant
directly so all references (output_instances, olimit, the for/while loop
conditions, and the assertion) consistently rely on the single named symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a786e7e5-3dca-4fbf-94e4-f75e5765d491

📥 Commits

Reviewing files that changed from the base of the PR and between 9d42647 and c6dcd3a.

📒 Files selected for processing (1)
  • tests/runtime/core_routes.c

@cosmo0920 cosmo0920 marked this pull request as draft March 20, 2026 06:49
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6dcd3a53a

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

@cosmo0920 cosmo0920 force-pushed the cosmo0920-handle-small-rlim_cur branch from c6dcd3a to d411694 Compare March 20, 2026 06:51
@cosmo0920 cosmo0920 marked this pull request as ready for review March 20, 2026 06:51
@cosmo0920 cosmo0920 requested a review from edsiper as a code owner March 20, 2026 06:51
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d411694b37

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

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.

🧹 Nitpick comments (1)
tests/runtime/core_routes.c (1)

53-53: Optional: extract 257 into a named constant to prevent drift.

257 is now used in multiple places for the same conceptual limit. A single named constant would make future edits safer and clearer.

♻️ Suggested refactor
+    const size_t max_outputs = 257;
-    size_t                olimit = 257;
+    size_t                olimit = max_outputs;
...
-    if (rlimit_rc == 0 && rlim.rlim_cur < 257) {
+    if (rlimit_rc == 0 && rlim.rlim_cur < max_outputs) {

Also applies to: 72-73

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtime/core_routes.c` at line 53, Extract the literal 257 into a
single named constant (e.g., MAX_PATH_LEN or CORE_ROUTES_OLIMIT) and replace the
hard-coded 257 in the declaration of olimit and the other occurrences referenced
(the two uses around the later block) with that constant; update any related
comments to reference the constant name so all uses share the same semantic
limit and future edits only change the constant definition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/runtime/core_routes.c`:
- Line 53: Extract the literal 257 into a single named constant (e.g.,
MAX_PATH_LEN or CORE_ROUTES_OLIMIT) and replace the hard-coded 257 in the
declaration of olimit and the other occurrences referenced (the two uses around
the later block) with that constant; update any related comments to reference
the constant name so all uses share the same semantic limit and future edits
only change the constant definition.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b516962-7122-47d3-a815-49b1ff26620e

📥 Commits

Reviewing files that changed from the base of the PR and between c6dcd3a and d411694.

📒 Files selected for processing (1)
  • tests/runtime/core_routes.c

By default, macOS's soft limit of rlimit is up to 256.
SO, just eating up 256 of output instances could cause too many open
errors.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
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.

1 participant