Skip to content

gh-162606: Avoid find_unused_port() races in asyncio tests - #162607

Open
asvetlov wants to merge 3 commits into
python:mainfrom
asvetlov:claude/cpython-ci-job-failure-2d136b
Open

asvetlov wants to merge 3 commits into
python:mainfrom
asvetlov:claude/cpython-ci-job-failure-2d136b

Conversation

@asvetlov

@asvetlov asvetlov commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Several asyncio tests picked a port with find_unused_port() and used it later, so a parallel test could take it in between.

  • Tests that expect a refused connection keep a bound, non-listening socket open for the whole test.
  • Servers bind to port 0 instead of a pre-picked port.
  • test_create_connection_local_addr retries on EADDRINUSE.

🤖 Generated with Claude Code

asvetlov and others added 2 commits November 25, 2026 07:03
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>
@asvetlov asvetlov added type-bug An unexpected behavior, bug, or error topic-asyncio skip news needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 25, 2026
@asvetlov asvetlov linked an issue Nov 25, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes 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.

Get rid of find_unused_port() in asyncio tests

1 participant