Skip to content

gh-93821: Keep asyncio proactor servers accepting after a connection reset - #161238

Open
asvetlov wants to merge 1 commit into
python:mainfrom
asvetlov:claude/cpython-93821-check-367525
Open

asvetlov wants to merge 1 commit into
python:mainfrom
asvetlov:claude/cpython-93821-check-367525

Conversation

@asvetlov

@asvetlov asvetlov commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

On Windows, a client that resets its connection while it waits in the listen queue makes the pending AcceptEx fail with ERROR_NETNAME_DELETED (WinError 64). BaseProactorEventLoop._start_serving treated every OSError as fatal for the listening socket and closed it. After that the server refused all new connections, while Server.is_serving() still returned True.

Changes:

  • IocpProactor.accept() closes the accept socket when AcceptEx fails, and turns ERROR_NETNAME_DELETED into ConnectionResetError, as recv() and friends already do. accept_coro no longer re-raises that error: the caller already receives it through the future, so re-raising only logged a second "Task exception was never retrieved" traceback.
  • The proactor serving loop treats ConnectionResetError and ConnectionAbortedError as per-connection errors: it logs them at debug level and keeps accepting, as SelectorEventLoop._accept_connection already does. Other OSErrors still close the listening socket.

Tests:

  • test_windows_events.test_accept_connection_reset reproduces the bug reliably, using the reproducer from the issue: two connections are made while the loop is blocked, and the second is reset in the listen queue. On a Windows 11 debug build it failed 3 times out of 3 without the fix (WinError 64, then ConnectionRefusedError) and passed 10 times out of 10 with it. The full test_asyncio suite passes on Windows.
  • test_proactor_events.test_create_server_connection_reset covers the serving-loop change with mocks.

Notes for reviewers:

🤖 Generated with Claude Code

…ction reset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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