Fix infinite loop in recv_inject() when peer closes connection#204
Closed
brndnsvr wants to merge 1 commit intoMarcJHuber:masterfrom
Closed
Fix infinite loop in recv_inject() when peer closes connection#204brndnsvr wants to merge 1 commit intoMarcJHuber:masterfrom
brndnsvr wants to merge 1 commit intoMarcJHuber:masterfrom
Conversation
6316718 to
55a3890
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an infinite loop bug in recv_inject() that occurred when a peer closed its side of the connection, causing high CPU usage (40-60% per process) and connections stuck in CLOSE_WAIT state. The fix replaces an incorrect two-way check with a proper three-way check to distinguish between successful data reception, EOF, and errors.
Key Changes:
- Replace
if (l > -1)with proper handling forrecv()return values: success (l > 0), EOF (l == 0), and errors (l < 0) - Move
inject_offreset inside the success block to prevent resetting on EOF/error - Add explicit status reporting for all code paths including buffered data returns
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The refill block in recv_inject() used `if (l > -1)` to check recv() return
value, which incorrectly treated EOF (recv returning 0) as valid data. This
caused tight CPU loops (40-60% per process) and CLOSE_WAIT connections when
peers closed their side of the connection.
Changes:
- Replace `if (l > -1)` with proper three-way check:
- l > 0: Success, set inject_len
- l == 0: EOF, set io_status_close and return
- l < 0: Error, handle EAGAIN/EWOULDBLOCK with io_status_retry,
others with io_status_error
- Reset inject_off only after successful recv()
- Add io_status_ok reporting when returning buffered data
55a3890 to
ae012aa
Compare
Owner
|
Hi Brandon, I didn't pull this due to overlaps with my local changes, but thanks anyway! Thanks, Marc |
Author
|
Thanks for the update. I'm happy to perform my same testing against the upstream's current and see what happens. Cheers! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The refill block in recv_inject() used
if (l > -1)to check recv() return value, which incorrectly treated EOF (recv returning 0) as valid data. This caused tight CPU loops (40-60% per process) and CLOSE_WAIT connections when peers closed their side of the connection.Changes:
if (l > -1)with proper three-way check: