Repository navigation
Spawn the detached child outside the temp dir in the socket-inherit test - #36971
Conversation
…erit test The Windows-only test added in #36938 spawns a detached child that inherits the parent's cwd, the test's temp dir. process.kill() only initiates TerminateProcess, so tempDir disposal races the child's teardown and rmSync fails with EBUSY on Windows. Give the child an explicit cwd outside the temp dir so it never holds the directory.
|
Warning Review limit reached
Next review available in: 12 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Comment |
There was a problem hiding this comment.
LGTM — test-only Windows CI flake fix.
What was reviewed:
- Confirmed
cwdis orthogonal to socket handle inheritance (lpCurrentDirectoryvsbInheritHandles), so the test still exercises the #36936 regression path. - The detached child runs
-e "setTimeout(...)"and reads nothing from cwd, so moving it toos.tmpdir()has no side effects on what's asserted. - Checked that the fix covers the failure path too (child never parsed → never killed → no longer holds the temp dir).
Extended reasoning...
Overview
This PR modifies a single Windows-only test fixture (test/js/node/child_process/child-process-socket-inherit.test.ts) to fix an EBUSY flake during tempDir disposal on the Windows 11 aarch64 CI lane. The change adds cwd: tmpdir() to the detached child's spawn options so the child no longer holds an open handle on the test's temp directory while it is being killed and cleaned up. Total diff: one import, one option, and a three-line explanatory comment.
Security risks
None. Test-only change; no runtime, native, or production code is touched. The child process already existed and already ran under os.tmpdir()'s parent hierarchy — this only changes which subdirectory it holds as cwd.
Level of scrutiny
Low. This is a targeted de-flake of test infrastructure with no behavioral change to what is being asserted. The key correctness question is whether adding cwd could accidentally mask the socket-inheritance bug the test guards against — it cannot, because CreateProcess's lpCurrentDirectory is independent of bInheritHandles, and the PR description confirms the test still fails when bsd.c is reverted to its pre-fix state. The child executes an inline -e script and needs nothing from its cwd.
Other factors
The PR description documents empirical verification on the exact failing lane (3/5 EBUSY before → 20/20 pass after) and confirms the negative case (reverted bsd.c still fails the assertion). The alternative considered — retrying EBUSY in the harness — was correctly rejected as it would hide real handle leaks elsewhere. The added comment is concise and explains the non-obvious "why" per repo conventions. No outstanding reviewer comments.
Fixes the Windows CI failure in
test/js/node/child_process/child-process-socket-inherit.test.ts, which has been failing on the Windows 11 aarch64 lane since the test landed in #36938 (for example in build 89207):Cause
The fixture spawns a detached child (
setTimeout(() => {}, 100000)) that inherits the parent's cwd, which is the test's temp dir. The test kills the child in itsfinally, but on Windowsprocess.killonly initiatesTerminateProcess: the process object, including its working directory handle, is released asynchronously.using dirdisposal runsfs.rmSyncimmediately after, so cleanup races the child's teardown and fails with EBUSY whenever the child has not finished dying. The socket assertions themselves pass (all 3 expect calls run); only cleanup fails. On the slower aarch64 runners the rm loses the race most of the time.It is worse on the failure paths: if the parent fixture exits non-zero,
childPidis never parsed, the kill never runs, and the child holds the temp dir for the full 100 seconds.Fix
Spawn the detached child with an explicit
cwdoutside the temp dir (os.tmpdir()). The child then never holds the directory that disposal removes, in every path, with no timing dependence.cwdis independent of handle inheritance (lpCurrentDirectoryvsbInheritHandlesinCreateProcess), so the code path exercised by the test is unchanged: the child is still spawned with inheritable-handle semantics while the listen socket is open.I considered retrying EBUSY in the harness
tempDirdisposal instead, but that would mask genuine process and handle leaks in every other Windows test.Verification (Windows 11 aarch64, the failing lane)
packages/bun-usockets/src/bsd.creverted to its pre-Create sockets with WSA_FLAG_NO_HANDLE_INHERIT on Windows #36938 state: fails withExpected: "ECONNREFUSED", Received: "connected", so the test still detects the original inherited-socket bug (Windows: detached child inherits listening socket and keeps port open after parent exits #36936).bsd.c: passes.The test is
skipIf(!isWindows), so Linux lanes are unaffected.