Skip to content

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

Open
devanshc777 wants to merge 1 commit into
python:mainfrom
devanshc777:fix/proactor-shutdown-reset
Open

devanshc777 wants to merge 1 commit into
python:mainfrom
devanshc777:fix/proactor-shutdown-reset

Conversation

@devanshc777

@devanshc777 devanshc777 commented Oct 29, 2026 •

Copy link
Copy Markdown

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

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.

1 participant