`FileFinder._find_children` can loop forever on a persistently failing directory scan
未关闭
还没有人认领这个 Issue。
stdlib
topic-importlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
- Location:
Lib/importlib/_bootstrap_external.py:1469(inside awhile True:loop, backing the newPathEntryFinder.discover()API, added 2026 via gh-139899)
- Problem: Scans a directory via
os.scandir(); anyOSErrorfromnext()or from an entry'sis_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 subsequentnext()raises the same error forever, and the loop never terminates: nobreak, no retry limit. - Reproducer (verified): patched
os.scandirto return an iterator whose__next__unconditionally raisesOSErrorforever;finder._find_children()under a 10-secondtimeoutwas 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 theexcept 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 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