io: wait for writable sockets before retrying sync writes#12116
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSynchronous socket writes now use ChangesSynchronous socket write wait
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f56c5c1e48
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Synchronous writes sleep for one second when send returns EAGAIN. This adds avoidable latency whenever a nonblocking socket buffer fills. Wait for POLLOUT before retrying so writes resume as soon as the socket can accept more data. Retry the write after poll wakes so peer-close errors reach the existing connection error handling. Preserve the one-second wait bound and 30-attempt limit. Signed-off-by: Stefano Tondo <stondo@gmail.com>
f56c5c1 to
abced0f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/internal/network.c`:
- Around line 324-395: Update
test_nonblocking_socket_write_propagates_peer_close to block or ignore SIGPIPE
around the flb_io_fd_write call, restoring the prior signal state afterward so
the test process survives the peer-close condition and can execute its existing
error assertions.
🪄 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: 60941f93-f271-452b-8cd1-4667ab831957
📒 Files selected for processing (2)
src/flb_io.ctests/internal/network.c
Use small nonblocking socket pairs to exercise temporary backpressure and a peer closing while the writer waits. Verify writes resume promptly and closed connections preserve a critical socket error. Signed-off-by: Stefano Tondo <stondo@gmail.com>
abced0f to
9b88c34
Compare
Summary
Replace the one-second sleep used by synchronous nonblocking socket writes
after
EAGAIN/EWOULDBLOCKwith a boundedPOLLOUTwait.Fixes #12115
Root cause
fd_io_write()currently sleeps for one full second wheneversend()orsendto()temporarily fills a nonblocking socket buffer. A large response canhit that path repeatedly, adding one second per backpressure event even when
the socket becomes writable much sooner.
Changes
POLLOUTfor at most one second before retrying;WSAPollon Windows, matching the existing network implementation;propagation using small nonblocking socket pairs.
Compatibility
There is no configuration or API change. The one-second upper bound and
30-attempt limit remain unchanged. The writer now resumes promptly when the
socket becomes writable instead of always waiting the full second.
The regression tests are POSIX-only because they use
socketpair()andpthreads. The Windows source path uses the same
WSAPollpattern present insrc/flb_network.c.Testing
Commands:
The tests ran in the documented Debian 12 rootless Podman environment. The
explicit AVX2 flag is a GCC 12 compatibility workaround for bundled
simdutf,not part of this change.
Results:
flb-it-network: passed 10 consecutive iterations;elapsed-time assertion, as expected;
EPIPE,ECONNRESET, orENOTCONNinstead ofreturning with stale
EAGAIN;git diff --check: passed;Live syscall evidence from the original reproduction:
Enter
[N/A]in the box, if an item is not applicable to your change.Testing
Packaging
Documentation
Backporting
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