Skip to content

gh-153133: Fix socket leak in asyncio create_connection#153134

Merged
kumaraditya303 merged 2 commits into
python:mainfrom
deadlovelll:gh-153133-socket-leak
Jul 7, 2026
Merged

gh-153133: Fix socket leak in asyncio create_connection#153134
kumaraditya303 merged 2 commits into
python:mainfrom
deadlovelll:gh-153133-socket-leak

Conversation

@deadlovelll

Copy link
Copy Markdown
Contributor

Close the socket in _create_connection_transport() when the transport is never created, not only on await failure

For more details see gh-153133

Comment thread Lib/asyncio/base_events.py Outdated
await waiter
except:
transport.close()
if transport is None:

@kumaraditya303 kumaraditya303 Jul 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like this to be split to 2 try blocks something like:

try:
    sock.setblocking(False)
    ...
    transport = self._make_socket_transport(...)
except:
    sock.close()
    raise
try:
    await waiter
except:
    transport.close()
    raise

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@kumaraditya303 kumaraditya303 merged commit 374920a into python:main Jul 7, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants