python / python/cpython

asyncio proactor server leaks the accepted socket and stops accepting when transport creation fails

未关闭
#156,365 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

OS-windows stdlib topic-asyncio type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

On the proactor event loop (the default on Windows), BaseProactorEventLoop._start_serving()'s loop() callback runs protocol_factory() and transport creation in the same callback that re-arms accept(), guarded only by except OSError / except CancelledError. When protocol_factory() or _make_ssl_transport() / _make_socket_transport() raises for an accepted connection:

  • a non-OSError (e.g. a failing protocol_factory) propagates out of loop(): the accepted socket is never closed (it leaks until garbage collection) and accept is not re-armed, so the server stops accepting new connections;
  • an OSError is caught as 'Accept failed on a socket', which closes the listening socket, and still leaks the accepted socket.

This is the proactor counterpart of gh-155934 (selector accept) and gh-153133 (create_connection): an accepted socket must be closed when the transport is never created, and a per-connection failure must not tear down the listening socket or the accept loop.

Verified with mock-based tests in test_proactor_events (the same approach used for the selector fix in gh-155934), which run on all platforms.

CPython versions tested on:

CPython main

Operating systems tested on:

Windows (ProactorEventLoop)

Linked PRs
  • gh-156366

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 BaseProactorEventLoop._start_serving() 和 test_proactor_events 中基于 mock 的测试开始。复现 protocol 或 transport 创建失败,然后验证已接受的 socket 已关闭,并且正在监听的服务器继续接受连接。在进行更改之前,比较已链接 PR gh-156366 中现有的工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
networking, operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。