Repository navigation
fix(ext/node): fix fs.glob skipping siblings with **/../* patterns - #33372
Merged
Merged
Conversation
The cache-seen check inside the children iteration loop used `return`, which aborted the entire `#addSubpatterns`/`#iterateSubpatterns` method. When a glob pattern contains `**/../*`, the ".." handler can queue the same path multiple times via the LIFO queue. If a duplicate entry is processed first (adding it to the cache), and then the parent directory iterates its children, a cached sibling would trigger the `return` and cut off all subsequent siblings -- which entries were skipped depended on the non-deterministic readdir ordering, causing flaky test failures. The fix changes `return` to `continue childrenLoop` so only the already-processed child is skipped while remaining siblings are still enumerated. Fixes flaky test-fs-glob.mjs node_compat failure.
The `continue childrenLoop` fix was insufficient: it correctly didn't abort siblings, but still skipped adding the cached child itself to results. When a path like `a/b` is processed via its own queue entry (recursing into its children), `a/b` itself is never added as a result. When the parent `a` later processes children with `*`, the cache check would skip `a/b` entirely, preventing it from appearing in results. The cache.seen check in the children loop is a redundant optimization. The `cache.add` call at the top of `#addSubpatterns`/`#iterateSubpatterns` already prevents reprocessing and infinite recursion. Removing the children-level check allows entries to be correctly added to results even when they were previously traversed from a different context.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test-fs-glob.mjsnode_compat test failure caused byfs.glob/fs.globSyncreturning incomplete results for patternscontaining
**/../*Root Cause
The
cache.seencheck inside the children iteration loop in both#addSubpatterns(sync) and#iterateSubpatterns(async) usedreturn,which aborted the entire method instead of just skipping the current
child.
When a glob pattern contains
**/../*, the..handler queues both thecurrent directory and its parent with the remaining
*pattern. Due torecursive directory traversal, the same path can get queued multiple
times. With the LIFO queue (
ArrayPrototypePop), a duplicate entry canbe processed first, adding it to the cache. When the parent directory
later iterates its children and encounters this cached entry, the
returncuts off all remaining siblings -- which entries are skippeddepends on the non-deterministic
readdirordering, causing flakyfailures.
Fix
Change
returntocontinue childrenLoop(labeled continue on theouter children loop) so only the already-processed child is skipped
while remaining siblings are still enumerated.
Note: upstream Node.js has the same
return-- this is a latent bugthere too, but it manifests more frequently on Linux CI due to different
readdirordering on ext4/tmpfs.Test plan
tests/unit_node/fs_test.tsthat creates adirectory structure triggering the duplicate-queue scenario
(
a/c/d/c/causes the..handler to re-queuea/c) and asserts allsiblings appear in
a/**/../*resultstools/format.jsandtools/lint.js --jspass