Repository navigation
Fix Bun.FileSystemRouter crashes on a directory listing that is not the one asked for, and reload() through a symlink
#46286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dylan-conway
wants to merge
7
commits into
main
Choose a base branch
from
claude/filesystem-router-dir-outside-base
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4b737e
Fix FileSystemRouter panic when a directory listing is not under the …
dylan-conway cf371ca
[autofix.ci] apply automated fixes
autofix-ci[bot] 43556f5
Use a directory listing in FileSystemRouter only if it is for the dir…
dylan-conway d058498
Merge branch 'claude/filesystem-router-dir-outside-base' of github.co…
dylan-conway 31ec893
Spell FileSystemRouter's dir as the resolver does when it is the curr…
dylan-conway d7bd6db
Use tempDir in the FileSystemRouter current directory test
dylan-conway 3550e45
Make the FileSystemRouter collision test reach the cached listing
dylan-conway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 (optional) When the colliding listing lives only in the resolver's entries cache, users get a router with zero routes and no error instead of the "Unable to find directory" error the PR promises for
diritself. The guard at src/runtime/api/filesystem_router.rs:129-134 checksinfo.abs_path, which is the requested path even when the DirInfo was filled from another directory'sDirEntry; the only check ofentries.diris the silentreturnat src/router/lib.rs:560-562, which also serves the top-level call. Fix: a mismatch of the top-level listing must surface the same way as adir_cachemismatch, e.g. haveload_all/loadreport it (or compareentries.dirinload_routertoo) so the constructor throws rather than returning an empty router, while a mismatched subdirectory stays skipped.Why this was flagged
read_directory(called fromload_as_fileat src/resolver/resolver.rs:5890) populates onlyrfs.entries, so a directory X can sit inrfs.entrieswithout adir_cacheslot. If a FileSystemRouterdirhashes like X,read_dir_info(&config.dir)missesdir_cache, opensdirsuccessfully, then at src/resolver/resolver.rs:4654-4671rfs!().entries.get_or_put(dir_path)hits X'sDirEntryand reuses it (needs_iter = false).dir_info_uncachedat src/resolver/resolver.rs:6192-6198 storesabs_path: path(the requesteddir) withentriespointing at X's listing. The new guard at src/runtime/api/filesystem_router.rs:129-134 comparesinfo.abs_pathtoconfig.dir, which match, so it accepts the DirInfo.RouteLoader::loadthen findsentries.dir= X unequal todirat src/router/lib.rs:560, and returns with no routes and no log entry;load_routerat src/runtime/api/filesystem_router.rs:150-154 sees no errors or warnings and returnsSome. On the base branch the loader walked X's listing (panic or wrong routes); the PR description says a mismatch fordiritself yieldsUnable to find directory, but this sibling path yields a silently empty router.Verification: Trigger: a
FileSystemRouterdirthat exists on disk and whose cache key collides with a listing that sits only inrfs.entries. At resolver.rs:4654-4666 the collidingDirEntryis reused, so the guard at src/runtime/api/filesystem_router.rs:129-131 passes and the only mismatch check is the bare return at src/router/lib.rs:560-562. The user gets a router that matches nothing, silently, rather than the promised error.