Skip to content

in_lib: Adjust consuming mechanism to improve throughput#12130

Open
cosmo0920 wants to merge 3 commits into
masterfrom
cosmo0920-increase-throughput-on-in_lib
Open

in_lib: Adjust consuming mechanism to improve throughput#12130
cosmo0920 wants to merge 3 commits into
masterfrom
cosmo0920-increase-throughput-on-in_lib

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Otherwise, Fluent Bit tests can fail as below on Windows:

126/163 Test  #35: flb-rt-filter_rewrite_tag ........................***Failed   59.15 sec
Test matched...                                 [ OK ]
Test not_matched...                             [ OK ]
Test keep_true...                               [ OK ]
Test heavy_input_pause_emitter...               [ OK ]
Test busy_emitter_keeps_original...             [ FAILED ]
  filter_rewrite_tag.c:435: Check got == heavy_loop... failed
    expect: 100000 got: 44307
Test issue_4518...                              [ OK ]
Test issue_4793...                              [ OK ]
Test sigsegv_issue_5846...                      [ OK ]
FAILED: 1 of 8 unit tests has failed.


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

  • Bug Fixes
    • Improved handling of large input payloads by reading data in a controlled loop, expanding the buffer as needed.
    • Added safer “no data” early exit to avoid unnecessary work.
    • Updated error handling for pipe read failures to better distinguish end-of-stream vs. other cases.
    • Improved buffer compaction after processing to retain remaining bytes correctly.
    • Strengthened initialization by validating nonblocking setup and performing cleanup on failures.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The in_lib plugin now performs bounded repeated reads with dynamic buffer growth, preserves unconsumed input, and validates channel and nonblocking setup with cleanup on initialization failures.

Changes

in_lib input handling

Layer / File(s) Summary
Channel initialization and nonblocking setup
plugins/in_lib/in_lib.c
in_lib_init validates channel initialization, configures nonblocking mode, and frees resources when setup fails.
Bounded buffered collection
plugins/in_lib/in_lib.h, plugins/in_lib/in_lib.c
in_lib_collect repeatedly reads available data up to LIB_MAX_READ_SIZE, grows the buffer, handles pipe conditions, and retains unconsumed bytes after parsing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: docs-required

Suggested reviewers: edsiper

Sequence Diagram(s)

sequenceDiagram
  participant InputChannel
  participant InLibCollector
  participant Pipe
  InputChannel->>InLibCollector: invoke collection
  InLibCollector->>Pipe: read available bytes
  Pipe-->>InLibCollector: bytes or terminal condition
  InLibCollector->>InLibCollector: grow buffer and retain unconsumed data
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: refactoring in_lib consumption to improve throughput.
✨ 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-increase-throughput-on-in_lib

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.

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
plugins/in_lib/in_lib.c (1)

52-93: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Apply the mandated C brace style.

The changed control blocks use same-line opening braces, while the supplied guideline requires opening braces on the next line. As per coding guidelines, C control blocks must place opening braces on the next line.

Also applies to: 237-253

🤖 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/in_lib/in_lib.c` around lines 52 - 93, Update the control blocks in
the affected read loop and the corresponding blocks around the referenced
additional section to place each opening brace on the next line, including the
while, if, else-if, and non-Windows conditional blocks. Preserve the existing
logic and indentation.

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.

Inline comments:
In `@plugins/in_lib/in_lib.c`:
- Around line 52-92: Update the file-descriptor setup for ctx->fd so the POSIX
pipe is also configured nonblocking, not only under FLB_SYSTEM_WINDOWS. Ensure
this setup occurs before the read loop in the surrounding initialization flow,
allowing the existing drain loop to continue until FLB_PIPE_WOULDBLOCK() on
non-Windows platforms.
- Around line 76-80: Update the error check in the read handling path to compare
errno directly with EPIPE rather than its negated value. Preserve the existing
-1 return for broken-pipe errors so they do not fall through to the successful
return path.

---

Nitpick comments:
In `@plugins/in_lib/in_lib.c`:
- Around line 52-93: Update the control blocks in the affected read loop and the
corresponding blocks around the referenced additional section to place each
opening brace on the next line, including the while, if, else-if, and
non-Windows conditional blocks. Preserve the existing logic and indentation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8329dfad-f7cd-477e-a56d-eec73fc2dea0

📥 Commits

Reviewing files that changed from the base of the PR and between 8a4c159 and 09c41bf.

📒 Files selected for processing (2)
  • plugins/in_lib/in_lib.c
  • plugins/in_lib/in_lib.h

Comment thread plugins/in_lib/in_lib.c Outdated
Comment thread plugins/in_lib/in_lib.c

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09c41bf1b4

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

Comment thread plugins/in_lib/in_lib.c
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
plugins/in_lib/in_lib.c (2)

71-81: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Propagate all non-would-block read errors.

After handling FLB_PIPE_WOULDBLOCK(), every other read() failure should remain an error. Returning 0 for errors other than EPIPE silently treats failures such as EBADF or EIO as successful no-data reads; return -1 instead, unless a specific errno has an explicitly documented benign meaning.

🤖 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/in_lib/in_lib.c` around lines 71 - 81, Update the bytes == -1 error
path in the pipe-reading function to return -1 for every non-would-block read
failure, including errors other than EPIPE. Preserve the existing
FLB_PIPE_WOULDBLOCK() break behavior and perror/flb_pipe_error handling.

52-65: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Bound the retained partial payload, not only each read.

total_bytes resets on every callback, while ctx->buf_len remains populated when decoding returns FLB_ERR_JSON_PART. An unterminated or malformed stream can therefore grow ctx->buf_data indefinitely across callbacks and exhaust memory. Enforce a maximum on ctx->buf_len, cap each read to the remaining capacity, and apply an explicit oversize/drop error path.

Also applies to: 100-105

🤖 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/in_lib/in_lib.c` around lines 52 - 65, Bound the retained partial
payload using ctx->buf_len, not the per-callback total_bytes counter. In the
read loop, limit each read to the remaining LIB_MAX_READ_SIZE capacity and
reject or drop input when ctx->buf_len reaches or would exceed that limit.
Ensure the oversize path reports the error and resets or discards the retained
buffer so malformed unterminated streams cannot grow ctx->buf_data across
callbacks.

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.

Outside diff comments:
In `@plugins/in_lib/in_lib.c`:
- Around line 71-81: Update the bytes == -1 error path in the pipe-reading
function to return -1 for every non-would-block read failure, including errors
other than EPIPE. Preserve the existing FLB_PIPE_WOULDBLOCK() break behavior and
perror/flb_pipe_error handling.
- Around line 52-65: Bound the retained partial payload using ctx->buf_len, not
the per-callback total_bytes counter. In the read loop, limit each read to the
remaining LIB_MAX_READ_SIZE capacity and reject or drop input when ctx->buf_len
reaches or would exceed that limit. Ensure the oversize path reports the error
and resets or discards the retained buffer so malformed unterminated streams
cannot grow ctx->buf_data across callbacks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eafa3b1f-1f6e-43a3-97ed-9a68a85f94d7

📥 Commits

Reviewing files that changed from the base of the PR and between 09c41bf and 5a573de.

📒 Files selected for processing (1)
  • plugins/in_lib/in_lib.c

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920 cosmo0920 changed the title in_lib: Adjust consuming mechanism to inprove throughput in_lib: Adjust consuming mechanism to improve throughput Jul 22, 2026
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