Skip to content

[3.14] gh-162606: Avoid find_unused_port() races in asyncio tests (GH-162607) - #162620

Merged
asvetlov merged 1 commit into
python:3.14from
miss-islington:backport-4b66b87-3.14
Nov 25, 2026
Merged

asvetlov merged 1 commit into
python:3.14from
miss-islington:backport-4b66b87-3.14

Conversation

@miss-islington

Copy link
Copy Markdown
Contributor

test_create_connection_local_addr_skip_different_family and
test_sock_client_fail expected a connect to an "unused" port to be
refused, but the port was not reserved, so a parallel test could start
listening on it and the connect would succeed. Keep a bound,
non-listening socket open for the duration of each test instead.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

Bind servers to port 0 instead of picking a port first and binding it
later, retry test_create_connection_local_addr on EADDRINUSE, and keep
the port of test_open_connection_happy_eyeball_refcycles reserved on
both loopback addresses so the connection is reliably refused.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

macOS and iOS fail a connect to a bound but non-listening port with
ETIMEDOUT immediately instead of ECONNREFUSED.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com


(cherry picked from commit 4b66b87)

Co-authored-by: Andrew Svetlov andrew.svetlov@gmail.com
Co-authored-by: Claude Opus 5.5 noreply@anthropic.com

…honGH-162607)

* pythongh-162606: Fix port races in asyncio connection-refused tests

test_create_connection_local_addr_skip_different_family and
test_sock_client_fail expected a connect to an "unused" port to be
refused, but the port was not reserved, so a parallel test could start
listening on it and the connect would succeed.  Keep a bound,
non-listening socket open for the duration of each test instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pythongh-162606: Avoid find_unused_port() races in more asyncio tests

Bind servers to port 0 instead of picking a port first and binding it
later, retry test_create_connection_local_addr on EADDRINUSE, and keep
the port of test_open_connection_happy_eyeball_refcycles reserved on
both loopback addresses so the connection is reliably refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pythongh-162606: Remove unused import in test_proactor_events

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pythongh-162606: Accept TimeoutError for non-listening ports on macOS

macOS and iOS fail a connect to a bound but non-listening port with
ETIMEDOUT immediately instead of ECONNREFUSED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------
(cherry picked from commit 4b66b873d07f69f90d93c74675d6989bd540512d)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@bedevere-app bedevere-app Bot added skip news topic-asyncio type-bug An unexpected behavior, bug, or error labels Nov 25, 2026
@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Nov 25, 2026
@asvetlov
asvetlov enabled auto-merge (squash) November 25, 2026 14:42
@asvetlov
asvetlov merged commit a6068e4 into python:3.14 Nov 25, 2026
57 checks passed
@miss-islington
miss-islington deleted the backport-4b66b87-3.14 branch November 25, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir topic-asyncio type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants