Skip to content

gh-155305: Preserve user-provided sockets on transport errors - #155341

Open
RealBhupesh wants to merge 2 commits into
python:mainfrom
RealBhupesh:agent/gh-155305-preserve-user-socket
Open

gh-155305: Preserve user-provided sockets on transport errors#155341
RealBhupesh wants to merge 2 commits into
python:mainfrom
RealBhupesh:agent/gh-155305-preserve-user-socket

Conversation

@RealBhupesh

@RealBhupesh RealBhupesh commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #155305.

Summary:

  • Keep caller-owned sockets open when transport creation fails.
  • Preserve cleanup for internally created sockets and accepted connections.

Tests:

  • ./python.exe -m test test_asyncio.test_base_events test_asyncio.test_events test_asyncio.test_unix_events (500 tests, 3 skipped)

@bedevere-app

bedevere-app Bot commented Aug 7, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@RealBhupesh
RealBhupesh marked this pull request as ready for review August 7, 2026 14:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68b960e9b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1244 to +1245
if not sock_was_provided:
sock.close()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore caller sockets' blocking mode on failure

When a caller supplies a blocking socket and protocol_factory() or transport construction raises, this branch now leaves the socket open even though _create_connection_transport() has already changed it to nonblocking at line 1226 (and create_unix_connection() does so before calling this helper). Because no transport was created and ownership remains with the caller, subsequent ordinary socket operations can unexpectedly raise BlockingIOError; preserve and restore the socket's original timeout/blocking state on this failure path.

Useful? React with 👍 / 👎.

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.

asyncio.loop.create_connection closes user-provided socket on transport creation failure (Regression in 3.14.7)

1 participant