You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pass# ignore exceptions from next(scan_iterator) and os.DirEntry
exceptStopIteration:
break
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.
Lib/importlib/_bootstrap_external.py:1469(inside awhile True:loop, backing the newPathEntryFinder.discover()API, added 2026 via IntroduceMetaPathFinder.discoverandPathEntryFinder.discover#139899)cpython/Lib/importlib/_bootstrap_external.py
Lines 1452 to 1472 in 1ad63cc
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.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.break(or a bounded retry counter) in theexcept OSError:branch.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
FileFinder._find_childrenretrying a failing directory scan #155939