Skip to content

[flow] Stop the file crawl at symlink cycles - #9535

Closed
robhogan wants to merge 2 commits into
meta:mainfrom
robhogan:stop-at-symlink-cycles
Closed

robhogan wants to merge 2 commits into
meta:mainfrom
robhogan:stop-at-symlink-cycles

Conversation

@robhogan

Copy link
Copy Markdown
Contributor

Fixes #9529

Last part of the stack #9532, #9533, #9534 (split from #9530).

#9534 stops the file crawl following a symlink to a directory it reads anyway, but it still follows any other symlink, eg out of the root or out of the directory passed to flow ls, and goes round a cycle of them until the OS refuses to resolve the path. With a few packages linked to each other, eg flow ls packages/a in a pnpm workspace, that never ends in practice.

This stops following a symlink to a directory the crawl passed through to reach it. Every walk now ends, though a dense web of links out of the crawl is still walked once per path through it, which grows quickly with the number of links.

Test plan:
symlinks_out_of_root now also has a cycle out of the root, whose files main lists once per lap. The full flow dev-tools runtests suite passes (macOS).

On react/metro installed with pnpm (react/metro#2110), flow ls packages/metro-config hangs on main. With this, flow ls of each workspace package finishes in under a second, and flow full-check gives the same result in the same time.

Fixes meta#9529

Last part of the stack meta#9532, meta#9533, meta#9534 (split from meta#9530).

meta#9534 stops the file crawl following a symlink to a directory it reads anyway, but it still follows any other symlink, eg out of the root or out of the directory passed to `flow ls`, and goes round a cycle of them until the OS refuses to resolve the path. With a few packages linked to each other, eg `flow ls packages/a` in a pnpm workspace, that never ends in practice.

This stops following a symlink to a directory the crawl passed through to reach it. Every walk now ends, though a dense web of links out of the crawl is still walked once per path through it, which grows quickly with the number of links.

Test plan:
`symlinks_out_of_root` now also has a cycle out of the root, whose files `main` lists once per lap. The full `flow dev-tools runtests` suite passes (macOS).

On react/metro installed with pnpm (react/metro#2110), `flow ls packages/metro-config` hangs on `main`. With this, `flow ls` of each workspace package finishes in under a second, and `flow full-check` gives the same result in the same time.
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

This pull request has been imported. If you are a Meta employee, you can view this in D133227488. (Because this pull request was imported automatically, there will not be any future comments.)

@meta-codesync meta-codesync Bot closed this in aaec865 Nov 19, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 19, 2026
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

This pull request has been merged in aaec865.

robhogan added a commit to robhogan/flow that referenced this pull request Nov 20, 2026
… the root's parent

Follow-up to meta#9534 and meta#9535, which stop the file crawl following a symlink to a directory it reads anyway or to one the walk is already in.

- A change to a TypeScript global declaration reinits the server, which crawls again in the same process. The crawl takes real paths from a process-wide canonicalization cache that was never cleared, so a symlink changed since it was cached still resolves to its old target: the new target's files go missing, and paths through the symlink resolve to the old one. This was already the case for symlinks the crawl follows, and meta#9534 extended it to the decision to skip one. An init from scratch now clears the cache before it crawls.
- `flow ls` of a directory containing the root, eg `flow ls ..`, treated a symlink under the root to anywhere in that directory as crawled directly, so files outside the root that it lists only through such a symlink went missing. The target now has to be under the root as well.

A reinit from saved state still keeps the cached targets. That's unchanged here.

Test plan:
New `symlink_change_before_reinit` test, which changes a symlink's target before a reinit, and `symlinks_out_of_root` now also lists `..`. Both fail without this change, and the new test also fails with `runtests --saved-state`. The full `flow dev-tools runtests` suite passes (macOS).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flow hangs crawling pnpm workspaces (symlink cycles in node_modules)

1 participant