Repository navigation
which: answer from the path when open(O_EXEC) fails with EMFILE or ENFILE
#47433
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
robobun
wants to merge
10
commits into
main
Choose a base branch
from
robobun/c3881697/which-probe-without-fd
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
10 commits
Select commit
Hold shift + click to select a range
f2f7eab
test: a PATH lookup finds a command when no descriptor is free
robobun 12f968e
test: temporary report on the macOS probe of a PATH candidate
robobun b8cef3f
test: widen the temporary report on the macOS probe
robobun 8aefc2c
test: add what this build's Bun.which does to the temporary report
robobun 303da38
[autofix.ci] apply automated fixes
autofix-ci[bot] 62bf3bb
which: answer from the path when open(O_EXEC) has no descriptor
robobun 0615609
test: keep the /bin/sh row, and pin the answer under an ACL
robobun dea021e
test: remove the temporary report on the macOS probe
robobun d6b198d
open: keep the read probe of the editor lookup
robobun 613b0c4
test: give both rows of the loop-init test a fixed PATH
robobun 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
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.
🟣 pre-existing, not blocking: macOS users with an ACL that denies readattr on an executable get two different Bun.which answers for the same file depending on how many descriptors are open. isExecutableFileByPath at src/jsc/bindings/c-bindings.cpp:96 starts with stat, which such an ACL refuses with EACCES, so the probe says no while open(O_EXEC) at c-bindings.cpp:104 says yes with a descriptor free. The PR accepts this as a trade-off, but the test at test/js/bun/util/which.test.ts:489 asserts withDescriptors equals withoutDescriptors, which this file class violates. Fix: skip the stat when it fails with EACCES and answer from faccessat(X_OK, AT_EACCESS) alone (it needs no readattr), keeping S_ISREG only when stat succeeds, so the two probes agree on this population too.
A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Trigger: a process on macOS with the descriptor table full (EMFILE at c-bindings.cpp:108) looks up a 0755 file whose ACL has
deny readattr; the PR's own measurement names this as the one fixture of 25 that differs. isExecutableFileByPath at c-bindings.cpp:96 requires stat to succeed before faccessat runs, and stat fails with EACCES under that ACL, so Bun.which returns null and spawn-by-name reports ENOENT "Executable not found in $PATH" (src/runtime/api/bun/js_bun_spawn_bindings.rs:138), where Node reports EMFILE. On the base branch the answer was also null, so this is not a regression on its own, but the PR's stated contract (doc at src/sys/lib.rs:3024: it "answers also when the process has no descriptor left") and its own test invariant (which.test.ts:489 withDescriptors toEqual withoutDescriptors) are not met for this file class. Remedy: when stat fails with EACCES, fall through to faccessat alone, so the probe matches open(O_EXEC) for readattr-denied executables.Verification: Trigger: macOS, descriptor table full, and the candidate on PATH is a 0755 file whose ACL denies readattr. A stat failure at src/jsc/bindings/c-bindings.cpp:96 short-circuits to false before faccessat is consulted. The equality assertion at test/js/bun/util/which.test.ts:489-499 never exercises the readattr case. On the base commit the same file under EMFILE already returned false.
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.
Not adopted. Without
statthe probe does not know what kind of file it has.faccessat(X_OK)alone also says yes for a directory that can be searched, and for a FIFO or a socket with the execute bits.open(O_EXEC)refuses all three on every Mac that was measured. So the change moves the disagreement to another kind of file. It does not remove it.readattrreturns the type.getattrlist(ATTR_CMN_OBJTYPE)needs the same right, and it failed withEACCESon this fixture.faccessatalone was not measured under this ACL on a Mac. That part is read from XNU.The case stays as the second bullet of Downsides. With no descriptor left, the answer for this file was
nullon main too. You are right that the test does not cover it: it has no fixture of this kind.