Skip to content

resolver: close the store_fd directory handle when readdir fails - #36878

Closed
robobun wants to merge 15 commits into
mainfrom
farm/067e1e57/resolver-readdir-err-fd-leak
Closed

robobun wants to merge 15 commits into
mainfrom
farm/067e1e57/resolver-readdir-err-fd-leak

close caller-supplied handle on the not-yet-published branch too

e3694ab
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Aug 4, 2026 in 18m 27s

Code review found 2 potential issues

Found 5 candidates, confirmed 2. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 2
🟣 Pre-existing 0
Severity File:Line Issue
🟡 Nit test/js/bun/resolve/resolver-readdir-error-fd-leak.test.ts:169-175 Second test's assertion neither proves the shim fired nor surfaces output on failure
🟡 Nit src/resolver/lib.rs:1171-1173 Doc comment overstates the maybe_handle ownership guarantee — pre-guard early returns still leak a caller-supplied fd

Annotations

Check warning on line 175 in test/js/bun/resolve/resolver-readdir-error-fd-leak.test.ts

See this annotation in the file changed.

@claude claude / Claude Code Review

Second test's assertion neither proves the shim fired nor surfaces output on failure

Unlike the first test — which asserts `FAILED=${DIR_COUNT}` per its own comment to prove the shim fired — this test only checks `LEAKED=0` / `stderr.includes("1 pass")` / `exitCode: 0`, all of which are also satisfied by a run where the shim never intercepted getdents64 (or the Scanner stopped passing `Some(handle)`), so it can go vacuous silently. Collapsing stderr to a boolean and stdout to a regex capture also means a failure diff shows `stderr: false` / `leaked: undefined` instead of what `b

Check warning on line 1173 in src/resolver/lib.rs

See this annotation in the file changed.

@claude claude / Claude Code Review

Doc comment overstates the maybe_handle ownership guarantee — pre-guard early returns still leak a caller-supplied fd

The new doc comment says `maybe_handle` is owned and "on any error before that it is closed", but the scopeguard is only armed at line 1235 — three exits precede it (`get_or_put(dir)?` at 1195, the cache-hit `cached => return Ok(cached)` at 1211, and the cached-NotFound return at 1213-1219) while `maybe_handle` is still an unconsumed `Option<Fd>` with no Drop. The Scanner passes `generation=0` after disarming its `Dir` via `into_raw()`, so the cache-hit return at 1211 is reachable in a normal `b