python / python/cpython

`FileFinder._find_children` can loop forever on a persistently failing directory scan

未關閉
#155,935 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-importlib type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

  • Location: Lib/importlib/_bootstrap_external.py:1469 (inside a while True: loop, backing the new PathEntryFinder.discover() API, added 2026 via gh-139899)

https://github.com/python/cpython/blob/1ad63ccc066a329180cfa8f4a8c4be8be47db973/Lib/importlib/_bootstrap_external.py#L1452-L1472

  • Problem: Scans a directory via os.scandir(); any OSError from next() or from an entry's is_dir()/is_file() is caught and ignored without breaking the loop. For a transient single-entry failure this is reasonable (skip and continue). But if the underlying condition is persistent — e.g. an NFS "stale file handle," a disconnected removable volume — every subsequent next() raises the same error forever, and the loop never terminates: no break, no retry limit.
  • Reproducer (verified): patched os.scandir to return an iterator whose __next__ unconditionally raises OSError forever; finder._find_children() under a 10-second timeout was killed (exit 124) — confirmed genuine hang. A companion test with a single transient injected error correctly skipped it and returned all real entries, confirming the "skip one bad entry" case works — it's specifically the persistent-failure case that hangs.
  • Suggested fix: Add a break (or a bounded retry counter) in the except OSError: branch.
  • Difficulty: Small, but a real hang bug (not just silent data loss) — worth flagging prominently. New code (2026), no existing discussion found.
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-155939

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/importlib/_bootstrap_external.py 第 1469 行附近開始,在 FileFinder._find_children 的掃描迴圈中執行 issue 中描述的持續失敗重現程式和暫時性錯誤配套測試。完成標準是:持續性的 OSError 掃描會終止,同時單一暫時性項目失敗仍允許傳回其餘項目。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。