Skip to content

gh-160429: Ignore ConnectionResetError from shutdown() when closing proactor sockets - #160909

Merged
asvetlov merged 2 commits into
python:mainfrom
devanshc777:fix/proactor-shutdown-reset
Nov 5, 2026
Merged

asvetlov merged 2 commits into
python:mainfrom
devanshc777:fix/proactor-shutdown-reset

Conversation

@devanshc777

@devanshc777 devanshc777 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, if the peer resets the connection after sending FIN, sock.shutdown(SHUT_RDWR) in _ProactorBasePipeTransport._call_connection_lost() raises ConnectionResetError (WinError 10054). The rest of the cleanup is skipped: the socket stays open, the transport is never detached from its server, and Server.wait_closed() never returns.

The connection is already gone at that point, so the reset is ignored, the same way _loop_reading() and _loop_writing() already treat ConnectionResetError as a normal end of the connection. Other shutdown() errors propagate as before.

Reproduced with real sockets on Windows 11 against a debug build of main: the server writes a response, the client half-closes without reading it, then closes, which sends a RST. Without the fix, 10 of 10 runs left the socket open (the debug build reports it as an unclosed-socket ResourceWarning) and wait_closed() hung; with the fix, 10 of 10 cleaned up. The added test uses a mocked socket, like test_call_connection_lost. test_asyncio passes on the same build.

gh-160600 was an earlier draft for this issue, closed by its author before review.

@python-cla-bot

python-cla-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Comment thread Lib/asyncio/proactor_events.py Resolved
@asvetlov asvetlov added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 4, 2026
@asvetlov
asvetlov merged commit 7b06d6f into python:main Nov 5, 2026
61 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @devanshc777 for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@asvetlov

asvetlov commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks, @devanshc777

@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

GH-161391 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 5, 2026
@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

GH-161392 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 5, 2026
asvetlov added a commit that referenced this pull request Nov 5, 2026
…osing proactor sockets (GH-160909) (#161392)

gh-160429: Ignore ConnectionResetError from shutdown() when closing proactor sockets (GH-160909)

* gh-160429: Ignore ConnectionResetError from shutdown() when closing proactor sockets

* Update Lib/asyncio/proactor_events.py

---------
(cherry picked from commit 7b06d6f)

Co-authored-by: Zap777 <124182405+devanshc777@users.noreply.github.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
asvetlov added a commit that referenced this pull request Nov 5, 2026
…osing proactor sockets (GH-160909) (#161391)

gh-160429: Ignore ConnectionResetError from shutdown() when closing proactor sockets (GH-160909)

* gh-160429: Ignore ConnectionResetError from shutdown() when closing proactor sockets

* Update Lib/asyncio/proactor_events.py

---------
(cherry picked from commit 7b06d6f)

Co-authored-by: Zap777 <124182405+devanshc777@users.noreply.github.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
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