Fix FD leak in connSocketBlockingConnect on timeout#3541
Open
madolson wants to merge 1 commit intovalkey-io:unstablefrom
Open
Fix FD leak in connSocketBlockingConnect on timeout#3541madolson wants to merge 1 commit intovalkey-io:unstablefrom
madolson wants to merge 1 commit intovalkey-io:unstablefrom
Conversation
25abc3b to
0e444b8
Compare
Assign conn->fd immediately after anetTcpNonBlockConnect() succeeds, so that the caller's connClose() properly cleans up the fd on any subsequent error (e.g., aeWait timeout). Previously, conn->fd was only assigned on success, so a timeout left the fd orphaned — one leak per failed MIGRATE connection attempt. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
0e444b8 to
7474835
Compare
xdk-amz
approved these changes
Apr 20, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3541 +/- ##
============================================
+ Coverage 76.41% 76.44% +0.02%
============================================
Files 159 159
Lines 79927 79927
============================================
+ Hits 61078 61097 +19
+ Misses 18849 18830 -19
🚀 New features to boost your workflow:
|
enjoy-binbin
approved these changes
Apr 22, 2026
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.
Summary
Fix a file descriptor leak in
connSocketBlockingConnect()whenaeWait()times out.Bug
When
anetTcpNonBlockConnect()succeeds butaeWait()times out (e.g., MIGRATE to an unreachable host), the fd is leaked because it was never assigned toconn->fd. The caller'sconnClose()checksconn->fd != -1and skips cleanup.Fix
Assign
conn->fd = fdimmediately afteranetTcpNonBlockConnect()succeeds, beforeaeWait(). This way the caller's normalconnClose()cleanup path handles the fd on any error, which is consistent with how the rest of the connection lifecycle works.TLS connections also benefit since
connTLSBlockingConnectdelegates to this function for the TCP layer.Reproducer
This issue was generated by AI but verified, with love, by a human.