fix(streams): wait for tcpip client connect instead of retrying - #3964
Draft
EmilyRagan wants to merge 1 commit into
Draft
EmilyRagan wants to merge 1 commit into
EmilyRagan wants to merge 1 commit into
Conversation
Retrying a non-blocking connect() treated EALREADY as connected. On macOS a refused connect still pending on retry returns EALREADY, so the client reported success. Wait for writability with connect_timeout (previously ignored) and read SO_ERROR for the real outcome. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3964 +/- ##
==========================================
+ Coverage 80.13% 80.15% +0.02%
==========================================
Files 901 901
Lines 68370 68374 +4
Branches 2699 2699
==========================================
+ Hits 54789 54808 +19
+ Misses 12913 12901 -12
+ Partials 668 665 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This branch has not been deployed
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
TcpipClientStream._connect(Python) spun on a non-blockingsocket.connect()and treatedEALREADYas success. If the handshake was still pending when the retry ran, the socket gotEALREADYand the stream reported connected, even when the connection was later refused.ECONNREFUSED, so CI (ubuntu-latest) passestest_raises_a_timeout_when_unable_to_connect.EALREADYfirst, and the test fails withConnectionRefusedError not raised.Fix
Follow the Ruby
connect_nonblockflow:connect_ex. OnEINPROGRESS/EWOULDBLOCK,selectfor writable (plus exceptional, for Windows) withconnect_timeout. That parameter was accepted before but never used.SO_ERRORfor the result. A non-zero errno is raised asOSError, which maps to its subclass (for exampleConnectionRefusedError).TimeoutError("Connect timeout ...").ValueError/EBADF/ENOTSOCK), raiseRuntimeError("Connect canceled"), as Ruby does.Tests
New tests in
test/streams/test_tcpip_client_stream.py: refused connection on an unused port, a successful connect to a listening server, the timeout path and the canceled path.On macOS,
test/streamsandtest/interfacespass (437 tests). Before the fix,test_raises_a_timeout_when_unable_to_connectfailed 3 out of 3 runs. It now passes.🤖 Generated with Claude Code