asyncio: Windows socket reset during Proactor cleanup skips socket closure and transport detachment
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
- #160600 de @OsmnvAslan — fechado sem integrar
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 70/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- backend, operating-systems
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 77.7k
- Forks
- 38.3k
- Merge médio
- 13h 43min
- PRs com merge (30d)
- 704
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/cpython
-
topic-socket type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160561 · 7 comentários ·
Mantenedores costumam responder em até 1 dia
-
tests topic-profiling type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#160334 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1CTalvez já em andamento @kinqsradio assumiu há 1 dia. Abertaextension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
Remove unused FVS_* macrosAbertainterpreter-core type-feature
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
python/cpython#160109 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160001 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
component:benchmark
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
agentic-os-org/ANOLISA#9177 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
distrochooser/distrochooser#520 ·
Mantenedores costumam responder em até 2 dias
-
Status: Needs confirmation Status: Needs triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
Mantenedores costumam responder em até 1 dia
-
[BUG] Published Docker images lack the redis extra: HEADROOM_COMPRESS_SESSION_STORE stops startupTalvez já em andamento @AlessandroSpallina assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
headroomlabs-ai/headroom#4513 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 65/100
codespell-project/codespell#4060 ·
Mantenedores costumam responder em até 1 dia