Skip to content

Spawn the detached child outside the temp dir in the socket-inherit test - #36971

Merged
dylan-conway merged 1 commit into
mainfrom
farm/3440d127/socket-inherit-test-ebusy
Aug 5, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
farm/3440d127/socket-inherit-test-ebusy

Conversation

@robobun

@robobun robobun commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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):

EBUSY: resource busy or locked, rm 'C:\Windows\Temp\buntmp-Fbshlf\socket-inherit_Ev5bLB'
    at [Symbol.dispose] (C:\buildkite-agent\build\test\harness.ts:462:8)

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 its finally, but on Windows process.kill only initiates TerminateProcess: the process object, including its working directory handle, is released asynchronously. using dir disposal runs fs.rmSync immediately 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, childPid is 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 cwd outside the temp dir (os.tmpdir()). The child then never holds the directory that disposal removes, in every path, with no timing dependence. cwd is independent of handle inheritance (lpCurrentDirectory vs bInheritHandles in CreateProcess), 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 tempDir disposal instead, but that would mask genuine process and handle leaks in every other Windows test.

Verification (Windows 11 aarch64, the failing lane)

The test is skipIf(!isWindows), so Linux lanes are unaffected.

…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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2668a94b-db1c-4c9d-bcd5-9b01e44145cd

📥 Commits

Reviewing files that changed from the base of the PR and between b58cd46 and 08ecb5f.

📒 Files selected for processing (1)
  • test/js/node/child_process/child-process-socket-inherit.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the claude label Aug 5, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only Windows CI flake fix.

What was reviewed:

  • Confirmed cwd is orthogonal to socket handle inheritance (lpCurrentDirectory vs bInheritHandles), so the test still exercises the #36936 regression path.
  • The detached child runs -e "setTimeout(...)" and reads nothing from cwd, so moving it to os.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.

@dylan-conway
dylan-conway merged commit 1f606e6 into main Aug 5, 2026
50 of 54 checks passed
@dylan-conway
dylan-conway deleted the farm/3440d127/socket-inherit-test-ebusy branch August 5, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants