python / python/cpython

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

Đang mở
#155,935 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-importlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

  • 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Lib/importlib/_bootstrap_external.py, khoảng dòng 1469, bên trong vòng lặp quét của FileFinder._find_children. Chạy reproducer cho lỗi dai dẳng và bài kiểm thử bổ sung cho lỗi tạm thời được mô tả trong issue. Hoàn thành khi việc quét với OSError dai dẳng kết thúc, trong khi một lỗi tạm thời duy nhất của một entry vẫn cho phép trả về các entry còn lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.