FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-155935: Stop `FileFinder._find_children` retrying a failing directory scan by tobiaspal · Pull Request #155939 · python/cpython · GitHub

Repository navigation

gh-155935: Stop FileFinder._find_children retrying a failing directory scan - #155939

Open
tobiaspal wants to merge 1 commit into
python:mainfrom
tobiaspal:gh-155935-find-children-loop
Open

tobiaspal wants to merge 1 commit into
python:mainfrom
tobiaspal:gh-155935-find-children-loop

Conversation

tobiaspal commented Aug 17, 2026 •
edited
Loading

Copy link
Copy Markdown

Split the OSError handling: an OSError from next() ends the listing, while one from is_dir() or is_file() skips just that entry.

FileFinder._find_children() (added by gh-139900 implementing the new PathEntryFinder.discover() API proposed in gh-139899) scans a directory in a while True: loop and ignores any OSError without ending the loop.

The except OSError: pass covers two different failure sources: next(scan_iterator) and the os.DirEntry methods. For a DirEntry method (is_dir()/is_file() racing a deletion), skipping the entry is correct. But when next(scan_iterator) itself fails persistently (stale NFS handle, disconnected removable volume) every retry raises the same OSError again, StopIteration never arrives, and the loop never terminates.

Found via @devdanzin's AI-assisted audit of Lib/; working on it at the PyCon Korea 2026 sprint.

Claude Code helped to write the tests and the fix.

…directory scan

Split the `OSError` handling: an `OSError` from `next()` ends the listing, while one from `is_dir()` or `is_file()` skips just that entry.
@@ -1454,6 +1454,13 @@ def _find_children(self):
while True:
try:
entry = next(scan_iterator)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why not simply entry = next(scan_iterator, None) followed by if entry is None? we're already assuming that the entry is non-None since we do entry.name just after next.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL