Skip to content

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

Merged
asvetlov merged 1 commit into
python:mainfrom
asvetlov:claude/cpython-93821-check-367525
Nov 4, 2026
Merged

asvetlov merged 1 commit into
python:mainfrom
asvetlov:claude/cpython-93821-check-367525

Conversation

@asvetlov

@asvetlov asvetlov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

If a client resets its connection while it waits in the listen queue, AcceptEx fails with ERROR_NETNAME_DELETED (WinError 64). The proactor serving loop then closes the listening socket, and the server stops accepting connections.

This PR turns that error into ConnectionResetError and closes the failed accept socket. The serving loop then keeps accepting on ConnectionResetError/ConnectionAbortedError, as the selector loop does.

test_accept_connection_reset reproduces the bug on Windows: without the fix it failed 3 runs out of 3, and with it the test passed 10 out of 10.

This supersedes gh-124032 and gh-124779.

🤖 Generated with Claude Code

…ction reset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@asvetlov
asvetlov marked this pull request as ready for review November 3, 2026 16:03
@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 f88565b into python:main Nov 4, 2026
59 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

GH-161308 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 4, 2026
@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

GH-161309 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 4, 2026
asvetlov added a commit that referenced this pull request Nov 4, 2026
…ection reset (GH-161238) (#161309)

gh-93821: Keep asyncio proactor servers accepting after a connection reset (GH-161238)
(cherry picked from commit f88565b)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
asvetlov added a commit that referenced this pull request Nov 4, 2026
…ection reset (GH-161238) (#161308)

gh-93821: Keep asyncio proactor servers accepting after a connection reset (GH-161238)
(cherry picked from commit f88565b)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Refleaks 3.15 (tier-3) has failed when building commit 0398aa1.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/2056/builds/483) and take a look at the build logs.
  4. Check if the failure is related to this commit (0398aa1) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/2056/builds/483

Failed tests:

  • test_imaplib

Failed subtests:

  • test_imaplib_timeout_functionality_test - test.test_imaplib.NewIMAPSSLTests.test_imaplib_timeout_functionality_test
  • test_imaplib_timeout_functionality_test - test.test_imaplib.NewIMAPTests.test_imaplib_timeout_functionality_test

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/test/test_imaplib.py", line 745, in test_imaplib_timeout_functionality_test
    client = self.imap_class("localhost", addr, timeout=0.001)
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1772, in __init__
    IMAP4.__init__(self, host, port, timeout)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 217, in __init__
    self.open(host, port, timeout)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1785, in open
    IMAP4.open(self, host, port, timeout)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 331, in open
    self.sock = self._create_socket(timeout)
                ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1775, in _create_socket
    sock = IMAP4._create_socket(self, timeout)
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 320, in _create_socket
    return socket.create_connection(address, timeout)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 887, in create_connection
    raise exceptions[0]
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 872, in create_connection
    sock.connect(sa)
    ~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 61] Connection refused


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/test/test_imaplib.py", line 745, in test_imaplib_timeout_functionality_test
    client = self.imap_class("localhost", addr, timeout=0.001)
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 217, in __init__
    self.open(host, port, timeout)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 331, in open
    self.sock = self._create_socket(timeout)
                ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 320, in _create_socket
    return socket.create_connection(address, timeout)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 887, in create_connection
    raise exceptions[0]
  File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 872, in create_connection
    sock.connect(sa)
    ~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 61] Connection refused

@asvetlov

asvetlov commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

The failure is not related to the change

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