Skip to content

gh-162059: Close the winning socket when happy eyeballs is cancelled - #162060

Open
cnzakii wants to merge 2 commits into
python:mainfrom
cnzakii:gh-162059-happy-eyeballs-cancel-leak
Open

cnzakii wants to merge 2 commits into
python:mainfrom
cnzakii:gh-162059-happy-eyeballs-cancel-leak

Conversation

@cnzakii

@cnzakii cnzakii commented Nov 15, 2026

Copy link
Copy Markdown

When loop.create_connection() runs with happy_eyeballs_delay and is cancelled after an attempt has connected but before staggered_race() returns, the race re-raises CancelledError and the connected socket is dropped until the garbage collector closes it.

create_connection() now records the sockets the attempts connect and closes them if the race raises. staggered_race() is unchanged and still propagates the cancellation.

The new test cancels create_connection() right after the only attempt has returned its socket; it fails without the fix.

…elled

When create_connection() runs with happy_eyeballs_delay and is cancelled
after an attempt connects but before staggered_race() returns, the race
re-raises CancelledError and drops the connected socket.  Record the
sockets the attempts connect and close them if the race raises.
@python-cla-bot

python-cla-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Comment thread Lib/asyncio/base_events.py Resolved
Pass a list to _connect_sock() instead of wrapping it, as suggested in
review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants