asyncio: Windows socket reset during Proactor cleanup skips socket closure and transport detachment
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #160600 来自 @OsmnvAslan —— 已关闭,未合并
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 77.7k
- 派生
- 38.3k
- 平均合并
- 13 小时 30 分钟
- 30 天内合并 PR
- 708
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenation未关闭performance stdlib
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
tests topic-profiling type-bug
难度 2/5 1-3 小时 新手友好度 78/100
python/cpython#160334 · 1 条评论 ·
维护者通常 1 天内回复
-
`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1C可能已有人在做 @kinqsradio 于 2 天前认领。 未关闭extension-modules type-bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
interpreter-core type-feature
难度 1/5 1 小时以内 新手友好度 78/100
python/cpython#160109 · 1 条评论 ·
维护者通常 1 天内回复
-
extension-modules type-bug
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#160001 · 3 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
glossyio/traffic-monitor#264 ·
维护者通常 1 天内回复
-
Add self-host未关闭
难度 1/5 1 小时以内 新手友好度 75/100
Atarity/deploy-your-own-saas#102 ·
-
[Bug]: RDFlex silently drops the covariate adjustment when the outcome or treatment column is integer-typed可能已有人在做 @vrjdev 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
DoubleML/doubleml-for-py#424 ·
维护者通常 1 天内回复
-
agentic-dmx docs enhancement
难度 1/5 1-3 小时 新手友好度 86/100
-
难度 1/5 1 小时以内 新手友好度 72/100
521xueweihan/HelloGitHub#4150 ·