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
分支
36k
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 摘要。