Repository navigation
gh-162877: unregister selector transport on init failure - #162882
Open
jlu-lujing wants to merge 1 commit into
Open
jlu-lujing wants to merge 1 commit into
jlu-lujing wants to merge 1 commit into
Conversation
jlu-lujing
requested review from
1st1,
asvetlov,
kumaraditya303 and
willingc
as code owners
November 30, 2026 17:40
|
The following commit authors need to sign the Contributor License Agreement: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #162877.
_SelectorTransport.__init__registers the new transport inloop._transportsbefore_SelectorSocketTransport.__init__performs the remaining setup. If setup then raises, for example when_set_nodelay()getsEINVALfrom a reset socket, the caller closes the socket but the transport remains registered and not closing. The kernel can reuse the fd, while_ensure_fd_no_transport()still rejects it. On the accept path this can leave a server resetting every new client while existing connections continue to work.This change wraps the post-registration initialization. If any exception escapes, the transport removes its own entry if that entry still refers to itself, detaches from its server, clears
_server, and re-raises. The regression test makes_set_nodelay()raiseOSErrorand verifies that the transport is detached and the fd is no longer considered in use.The issue reports this regression in 3.14.8 and later, so a backport to 3.14 may be appropriate.
Validation:
_server._detach()is never called, and passes after the fix../python.exe -m test test_asyncio.test_selector_events: 137 tests passed../python.exe -m test test_asyncio: 3,089 tests run, 76 skipped, 0 failed across 33 passing test files.make patchcheck: passed.This patch was prepared with assistance from OpenAI Codex; I reviewed the analysis against the failing test and the complete asyncio test suite.