Repository navigation
Conversation
Three separate investigations (#31688, the inspector temp-dir disposal fix, and #36971) each re-derived the same cause for a bare EBUSY thrown by tempDir disposal on Windows: a process spawned by the test still holds the directory as its cwd while terminating. Augment the error in DisposableString's dispose paths and rmScope with that diagnosis (the error is still thrown, with code/errno intact), and document the rule in test/CLAUDE.md.
WalkthroughThe test harness adds Windows diagnostics for temporary-directory removal failures. Synchronous and asynchronous cleanup paths, including ChangesWindows test cleanup
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/harness.ts`:
- Around line 471-493: Add Windows-focused regression tests for
rethrowWithRmDiagnostic and DisposableString cleanup, simulating process-handle
failures to verify the original error propagates with the appended diagnostic
text. Exercise synchronous disposal, asynchronous disposal, and rmScope, and
also verify non-matching errors retain their unchanged message and behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0ca7c677-cca8-4396-97b7-ffe7c169b51e
📒 Files selected for processing (2)
test/CLAUDE.mdtest/harness.ts
There was a problem hiding this comment.
LGTM — test-harness-only diagnostic that appends guidance to Windows EBUSY/EPERM errors during temp-dir disposal without changing success-path behavior.
What was reviewed:
rethrowWithRmDiagnosticalways throws (return typenever), so neither the sync try/catch nor the async.catch()swallows the error — tests still fail on a held directory.- Non-Windows and non-EBUSY/EPERM paths rethrow the original error unchanged;
code/errno/syscall/pathare preserved since the same object is rethrown. - The
pathparameter name doesn't shadow any module-level import (onlydirname/isAbsolute/joinare imported frompath).
Extended reasoning...
Overview
This PR touches two test-infrastructure files: test/harness.ts adds a rethrowWithRmDiagnostic helper wrapping the three temp-dir cleanup sites (DisposableString[Symbol.dispose], DisposableString[Symbol.asyncDispose], and rmScope), and test/CLAUDE.md gains one paragraph documenting the Windows cwd-handle behavior. No runtime, native, or user-facing code is touched.
Security risks
None. This is test-harness-only code that appends a string to an error message on the failure path. It does not touch auth, crypto, network, or any production surface.
Level of scrutiny
Low. The change is confined to error handling in test cleanup helpers. The only behavioral question is whether errors could be accidentally swallowed, and the answer is no: rethrowWithRmDiagnostic unconditionally ends with throw error, so the sync path rethrows and the async .catch(error => rethrowWithRmDiagnostic(...)) rejects the returned promise. On non-Windows or non-matching error codes the message is left untouched and the original error object is rethrown, so nothing that previously failed will now pass.
Other factors
The PR description cites three prior independent bisections of the same root cause (#31688, ecaa553, #36971), which is exactly the situation where centralizing the diagnostic in the harness is the right layer per REVIEW.md's "fix bugs at the layer that owns the violated invariant" guidance. The change deliberately does not retry or suppress (which #36971 rejected), keeping held directories a hard failure. Verification was done on Windows aarch64 by reproducing the pre-#36971 failure and confirming the new message appears, and success paths were checked on both Windows and Linux.
…test A live child with its cwd inside the temp dir makes every disposal path (sync, async, rmScope) fail with the appended diagnostic and an intact error code; non-matching errors pass through unchanged. The child prints before the dir is touched because its cwd handle is established by the child-side loader after CreateProcess returns.
There was a problem hiding this comment.
LGTM — test-infrastructure-only change that appends a diagnostic hint to an already-thrown error.
What was reviewed:
rethrowWithRmDiagnosticalways rethrows; success paths and non-Windows/non-matching error paths are byte-identical to before.- Async dispose's
.catchhandler throws via thenever-returning helper, so the returned promise still rejects — no swallowing. - New Windows test kills the child and polls cleanup in
finally; the NUL-path pass-through test and both success-path tests run on all platforms.
Extended reasoning...
Overview
This PR touches only test infrastructure: test/harness.ts (wraps three temp-dir cleanup sites in try/catch to append a diagnostic to Windows EBUSY/EPERM before rethrowing), test/CLAUDE.md (one paragraph documenting the pattern), and a new test/internal/harness-rm-diagnostic.test.ts. No runtime code is touched.
Security risks
None. The change only mutates error.message on an error object that was already being thrown from test cleanup. No new inputs are parsed, no new syscalls, no auth/crypto/network paths.
Level of scrutiny
Moderate — test/harness.ts is loaded by every test file, so a top-level fault would break the whole suite. I checked that the additions are a function definition plus try/catch wrappers with no top-level side effects, and that the success path (rmSync returns normally) is unchanged. The failure-path change is purely additive: the same error object is rethrown with code/errno/syscall/path intact and only .message extended, gated on process.platform === 'win32' plus a specific errno match. The async-dispose wrapper uses .catch(e => rethrowWithRmDiagnostic(e, ...)) where the helper is never-returning, so the promise still rejects and await using still surfaces the failure.
Other factors
- The regression test is well-structured: the Windows case waits for the child's readiness line before asserting, cleans up in
finallywith a bounded poll (the exact pattern REVIEW.md prescribes for "X eventually happens"), and the cross-platform tests cover the pass-through and success paths so non-Windows CI still exercises the new catch blocks. - CodeRabbit's only feedback (add tests) was addressed in cb344c9 and marked resolved.
- The author verified on Windows 11 aarch64 (15/15) and Linux; the PR description shows the actual augmented error output.
- The new test file lives in
test/internal/alongside other harness/internal tests, which is the right home.
Given the change is small, additive, test-only, and cannot alter behavior on the happy path, I'm approving.
…iagnostic A process.chdir() into the temp dir that is not restored produces the same Windows EBUSY as a child process holding the dir, but the child-process advice misdirects that case. Detect it from process.cwd() and point at restoring the cwd instead, document it in test/CLAUDE.md, and pin both branches in the regression test.
There was a problem hiding this comment.
LGTM — test-harness-only change that appends a diagnostic to Windows EBUSY/EPERM on temp-dir disposal and rethrows; success paths are unchanged.
What was reviewed:
rethrowWithRmDiagnosticalways rethrows (return typenever), so no failure is swallowed; async dispose's.catchhandler throws → promise still rejects.- Non-Windows and non-EBUSY/EPERM paths short-circuit and rethrow the original error untouched;
code/errno/syscall/pathstay intact since only.messageis appended. - Regression tests: child-holder test awaits the child's "ready" line before asserting (avoids the CreateProcess race), restores
process.chdirinfinally, cleanup polls with a bounded deadline;rmScope("\0")is a portable pre-syscall validation error that won't match the diagnostic guard.
Extended reasoning...
Overview
This PR touches three files, all in the test tree: test/harness.ts (adds rethrowWithRmDiagnostic and wraps the three temp-dir disposal call sites — DisposableString[Symbol.dispose], [Symbol.asyncDispose], and rmScope — in try/catch that rethrows through it), test/CLAUDE.md (a paragraph documenting the Windows cwd-hold pitfall), and a new test/internal/harness-rm-diagnostic.test.ts regression file. No runtime, native, or shipped code is touched.
Security risks
None. This is test-infrastructure error-message enrichment only. The diagnostic is gated behind process.platform === "win32" and specific errno codes, mutates only error.message, and always rethrows.
Level of scrutiny
Low-medium. test/harness.ts is imported by every test file, so a mistake here would break the whole suite — but the change is purely additive around already-throwing failure paths. On success (rmSync/rm completes), execution is byte-identical to before. On failure, the same error object is rethrown with an appended message on Windows only. The async-dispose wrapper returns promise.catch(handler) where the handler throws, so the returned promise still rejects — no swallow. The sep import addition is trivial.
Other factors
- The cwd-inside check lowercases both sides and appends the platform separator before
startsWith, soC:\\foodoesn't false-matchC:\\foobar, andprocess.cwd()is wrapped in try/catch in case the cwd itself was deleted. - The regression tests follow harness conventions:
test.skipIf(!isWindows)for the platform-specific cases,bunEnv/bunExe, awaiting the child's readiness line rather than sleeping, restoring mutated global state (process.chdir) infinally, and a bounded poll loop (100 × 50ms) for the asynchronous handle-release cleanup. The non-matching-error case uses a NUL-byte path, which fails Node's argument validation before any syscall on every platform and carries noEBUSY/EPERMcode. - CodeRabbit's only feedback (add regression tests) was addressed in cb344c9 and marked resolved. No CODEOWNERS apply to these paths. No prior reviews from me on this PR.
|
CI note: the only hard failure in build 89258 is test/js/node/async_hooks/AsyncLocalStorage-tracking.test.ts on the x64-asan lane, a pre-existing leak on main that is unrelated to this PR (it was red in builds 89222 and 89243 as well, and predates these commits). The other failures passed on retry. Everything this PR touches is green, including the new regression tests on every Windows lane. |
|
Closing this PR because it has been inactive for more than 90 days. |
|
The inactivity sweep closed this PR, and it can stay closed. Main solved the same failure in a different way after I opened this PR.
One part is not on main. It is the message that explains the cause when a process holds the folder past the retry. If someone wants that message, a new and smaller change on top of the retry is the way to add it. |
Follow-up to #36971. When
tempDirdisposal fails with EBUSY on Windows, the harness currently surfaces a bare filesystem error:That error has now been independently bisected to the same root cause three times, each investigation ending in a per-test fix plus a locally worded comment:
test/cli/run/crash-report-command-char.test.ts(Record the running CLI command in crash report trace strings #31688): crash-reporter child inherits the temp dir as cwdtest/js/node/inspector/inspector.test.ts(ecaa553):--inspect-brkchild held the temp dir as cwdtest/js/node/child_process/child-process-socket-inherit.test.ts(Spawn the detached child outside the temp dir in the socket-inherit test #36971): detached child inherits the temp dir as cwdThe cause is always a process holding the directory as its cwd (or an open handle inside it) when disposal runs: either a process spawned by the test, including one already killed (
TerminateProcessreleases handles asynchronously), or the test process itself after aprocess.chdir()into the dir that was not restored.Change
test/harness.ts: whenrmSync/rminDisposableString's dispose paths orrmScopefails with EBUSY or EPERM on Windows, append the diagnosis to the error message and rethrow. The two holder classes get different advice: ifprocess.cwd()is inside the directory the message says to restore the cwd before cleanup (chdir back in afinally, or declarecwdScopeaftertempDirso it is undone first); otherwise it points at the spawned-process fixes (await the child's exit, or spawn it with a cwd outside the temp dir). The original error object is rethrown unchanged otherwise:code,errno,syscall,path, and the stack stay intact, and the test still fails. No retry and no swallow, so a held directory remains a hard failure (a retry would mask genuine process and handle leaks, which is why Spawn the detached child outside the temp dir in the socket-inherit test #36971 rejected it).test/CLAUDE.md: document both rules in the "Spawning processes" section, since the canonical multi-file example teachescwd: String(dir)and any child that outlives the test reproduces this.test/internal/harness-rm-diagnostic.test.ts: regression tests. A live child with its cwd inside the dir makes sync disposal, async disposal, andrmScopeall fail with the spawned-process diagnostic and an intact EBUSY/EPERM code; aprocess.chdir()into the dir produces the own-cwd diagnostic instead; non-matching errors (a pre-syscall validation error, portable to all platforms) pass through untouched; and the success paths still remove their directories on every platform.Verification (Windows 11 aarch64)
Restored the pre-#36971 fixture (detached child inheriting the temp dir cwd) to trigger the real failure through the new path; the test now fails with:
The regression tests pass 10/10 consecutive runs on Windows 11 aarch64 and on Linux (where the Windows-only cases skip). Success paths are unchanged:
tempDirsync dispose,tempDirasync dispose, andrmScopeall still remove their directories, and the socket-inherit test passes 5/5 with the modified harness.One detail the child-holder regression test encodes: a spawned child's cwd handle is established by the child-side loader after
CreateProcessreturns, so the test waits for the child to print before asserting removal fails. The same window is why the original flake in #36971 was intermittent rather than constant.no test proof · iteration 0 · Platform-specific test-only change; deferring to CI.