Title: `FileFinder._find_children` can loop forever on a persistently failing directory scan · Issue #155935 · python/cpython · GitHub
Open Graph Title: `FileFinder._find_children` can loop forever on a persistently failing directory scan · Issue #155935 · python/cpython
X Title: `FileFinder._find_children` can loop forever on a persistently failing directory scan · Issue #155935 · python/cpython
Description: Location: Lib/importlib/_bootstrap_external.py:1469 (inside a while True: loop, backing the new PathEntryFinder.discover() API, added 2026 via gh-139899) cpython/Lib/importlib/_bootstrap_external.py Lines 1452 to 1472 in 1ad63cc def _fin...
Open Graph Description: Location: Lib/importlib/_bootstrap_external.py:1469 (inside a while True: loop, backing the new PathEntryFinder.discover() API, added 2026 via gh-139899) cpython/Lib/importlib/_bootstrap_external.p...
X Description: Location: Lib/importlib/_bootstrap_external.py:1469 (inside a while True: loop, backing the new PathEntryFinder.discover() API, added 2026 via gh-139899) cpython/Lib/importlib/_bootstrap_external.p...
Opengraph URL: https://github.com/python/cpython/issues/155935
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`FileFinder._find_children` can loop forever on a persistently failing directory scan","articleBody":"- **Location:** `Lib/importlib/_bootstrap_external.py:1469` (inside a `while True:` loop, backing the new `PathEntryFinder.discover()` API, added 2026 via gh-139899)\n\nhttps://github.com/python/cpython/blob/1ad63ccc066a329180cfa8f4a8c4be8be47db973/Lib/importlib/_bootstrap_external.py#L1452-L1472 \n\n- **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.\n- **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.\n- **Suggested fix:** Add a `break` (or a bounded retry counter) in the `except OSError:` branch.\n- **Difficulty:** Small, but a real hang bug (not just silent data loss) — worth flagging prominently. New code (2026), no existing discussion found.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155939\n* gh-162324\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tobiaspal","@type":"Person","name":"tobiaspal"},"datePublished":"2026-08-17T06:05:53Z","url":"https://github.com/python/cpython/issues/155935"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c655e0df-a4f3-7fae-12c7-62f220b509e9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 884E:23E48:1CE408:248759:6B0202AA |
| html-safe-nonce | ebef0850c3529b046cc051088449ab0541c9b8bfee83c7dfc36554956ee87b77 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODRFOjIzRTQ4OjFDRTQwODoyNDg3NTk6NkIwMjAyQUEiLCJ2aXNpdG9yX2lkIjoiODY0NTI5NjY1NzgxNjIyNDQyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ceb4fda5f1f6196624ce98dfb11cd0fed71031979ba76bd592f16531859f4cf8 |
| hovercard-subject-tag | issue:5168814576 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/155935/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fa6d189efa6aa0de952edbdddd4acfc55d28a5724e5ee88e14575cd574c978ac/python/cpython/issues/155935 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fa6d189efa6aa0de952edbdddd4acfc55d28a5724e5ee88e14575cd574c978ac/python/cpython/issues/155935 |
| og:image:alt | Location: Lib/importlib/_bootstrap_external.py:1469 (inside a while True: loop, backing the new PathEntryFinder.discover() API, added 2026 via gh-139899) cpython/Lib/importlib/_bootstrap_external.p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tobiaspal |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width