asyncio: Windows socket reset during Proactor cleanup skips socket closure and transport detachment
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
- #160600 par @OsmnvAslan — fermée sans fusion
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 70/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- python
- Domaine
- backend, operating-systems
Piste de recherche
Start by reading _ProactorBasePipeTransport._call_connection_lost() in Lib/asyncio/proactor_events.py and the related asyncio transport tests. Use the provided mock-based reproducer to check that a shutdown reset does not skip socket closure, server detachment, or completion marking, while exceptions from protocol.connection_lost() and unexpected shutdown failures remain visible. Done means those cleanup steps run for the expected reset and the regression is covered by a test.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug description
On Windows, _ProactorBasePipeTransport._call_connection_lost() can raise ConnectionResetError: [WinError 10054] from self._sock.shutdown(socket.SHUT_RDWR) while cleaning up a connection. The exception escapes into the event loop's exception handler before the subsequent socket closure, server detachment, and _called_connection_lost = True execute.
This was observed in an active application on CPython 3.14.5 (Windows), producing Exception in callback _ProactorBasePipeTransport._call_connection_lost() errors. The application continued running. The defect is the interrupted cleanup, beyond the unexpected error log: a socket can remain open until later finalization, and transport bookkeeping remains incomplete.
Deterministic reproducer
This standard-library-only example injects the observed socket-shutdown error and calls the unmodified CPython cleanup method. It demonstrates the skipped cleanup without depending on network timing; it does not reproduce the original TCP reset timing. Run it on Windows in a fresh interpreter without an application-installed asyncio patch.
from asyncio.proactor_events import _ProactorBasePipeTransport
from types import SimpleNamespace
from unittest.mock import Mock
reset = ConnectionResetError("connection reset during shutdown")
reset.winerror = 10054
sock = Mock()
sock.shutdown.side_effect = reset
server = Mock()
transport = SimpleNamespace(
_called_connection_lost=False,
_protocol=Mock(),
_sock=sock,
_server=server,
)
try:
_ProactorBasePipeTransport._call_connection_lost(transport, None)
except ConnectionResetError:
print("ConnectionResetError escaped cleanup")
print("socket.close calls:", sock.close.call_count)
print("server detach calls:", server._detach.call_count)
print("cleanup complete:", transport._called_connection_lost)
Observed output on CPython 3.14.5:
ConnectionResetError escaped cleanup
socket.close calls: 0
server detach calls: 0
cleanup complete: False
Expected behavior
An already-reset socket should still be closed and the transport detached and marked complete. Handle the expected reset around the socket shutdown operation, while ensuring remaining cleanup runs. Exceptions from protocol.connection_lost() and unexpected shutdown failures should remain observable; broadly suppressing exceptions around the whole callback would hide unrelated failures.
A potential improvement would prevent noisy error log messages by catching 'reasonable' shutdown failures and logging them via asyncio's debug logger (if debug mode is enabled for that proactor transport's event loop). Either way, shutdown errors should not cause cleanup to be skipped.
CPython versions tested on
CPython 3.14.5, Windows x86-64. Both the application traceback and the deterministic reproducer were observed on this version.
Source inspection, rather than execution on those interpreters, found the same method implementation in releases 3.14.6–3.14.9 and 3.15.0–3.15.1. See the 3.14.5 source and 3.15.1 source.
Related reports
- The same shutdown traceback appears in a comment on #125981, a closed issue about
SSL: APPLICATION_DATA_AFTER_CLOSE_NOTIFY. I could not find a dedicated issue tracking the interrupted Proactor socket cleanup. - #149388 concerned
WinError 6fromPipeHandle.close()in this callback. That issue was fixed inPipeHandle; this report concernsWinError 10054from the preceding socketshutdown()call.
Linked PRs
- gh-160600
- Langage dominant
- Python
- Étoiles
- 77.8k
- Forks
- 37.7k
- Merge moyen
- 12 h 14 min
- PR mergées (30 j)
- 729
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
tests topic-profiling type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
python/cpython#160881 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
3.16 build pending type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
python/cpython#160829 · 5 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
dependencies infra topic-ensurepip
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 1 jour
-
symtable: repr() of a Symbol raises TypeError under -X lazy_imports=allPeut-être pris @anistark l’a pris il y a 1 jour. Ouvertestdlib topic-lazy-imports type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/cpython#160810 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationPeut-être pris @devdavidejesus l’a pris il y a 1 jour. Ouverteperformance stdlib triaged type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
python/cpython#160774 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/cpython
Issues similaires
-
ai_p2 bug comp-datalake
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
ClickHouse/ClickHouse#128306 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug] PROPOSE docs promise approval before saving, but save_learning has no confirmation flagOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
[bug] openlit: LLM spans from openlit 1.37+ get no OpenInference attributes, and cache and reasoning token counts are droppedPeut-être pris @sohom-cs l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Arize-ai/openinference#4199 · 1 réaction ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
MichaelYcJo/SpecSeal#1192 ·