Skip to content

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

Merged
FFY00 merged 1 commit into
python:mainfrom
tobiaspal:gh-155935-find-children-loop
Nov 20, 2026
Merged

FFY00 merged 1 commit into
python:mainfrom
tobiaspal:gh-155935-find-children-loop

Conversation

@tobiaspal

@tobiaspal tobiaspal commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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.

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.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Nov 17, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Nov 20, 2026
@FFY00
FFY00 merged commit 4d342eb into python:main Nov 20, 2026
59 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Nov 20, 2026
@FFY00 FFY00 added the needs backport to 3.15 bugs and security fixes label Nov 20, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @tobiaspal for the PR, and @FFY00 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 20, 2026

Copy link
Copy Markdown

GH-162324 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 20, 2026
FFY00 pushed a commit that referenced this pull request Nov 20, 2026
… directory scan (GH-155939) (#162324)

Co-authored-by: Paul Tobias <github@tobias.pt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint stale Stale PR or inactive for long period of time.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants