Skip to content

fix: add exit event fallback for child process close hang on Windows#26147

Open
bingkxu wants to merge 1 commit intoanomalyco:devfrom
bingkxu:fix/windows-childprocess-close-hang
Open

fix: add exit event fallback for child process close hang on Windows#26147
bingkxu wants to merge 1 commit intoanomalyco:devfrom
bingkxu:fix/windows-childprocess-close-hang

Conversation

@bingkxu
Copy link
Copy Markdown

@bingkxu bingkxu commented May 7, 2026

Issue for this PR

Closes #24784

Replaces #24783 (stale - branch diverged from dev and could no longer merge cleanly).

Type of change

  • Bug fix

What does this PR do?

On Windows, when a child process spawns grandchild processes (e.g., build tools like hvigor/Gradle daemons), the grandchild may inherit the stdout/stderr pipe handles. Even after the direct child exits, these inherited handles keep the pipe open, preventing Node.js close event from firing.

The exitCode in cross-spawn-spawner.ts was resolved only on close event, causing bash tool to hang indefinitely in Effect.raceAll waiting for handle.exitCode.

This PR adds a fallback: resolve exitCode on exit event with a 2-second delay. If close fires within 2 seconds (normal case), behavior is unchanged. If close does not fire (daemon holds pipe), fallback resolves after 2 seconds.

How did you verify your code works?

  1. Typecheck passes: bun typecheck in packages/core
  2. New test added for the Windows-specific fallback scenario
  3. Logic identical to fix: add exit event fallback for child process close hang on Windows #24783, rebased on latest dev

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found

PR #24783 - #24783

  • Reason: This is the stale PR that the current PR (26147) explicitly replaces. It has the same fix but the branch diverged from dev and could no longer merge cleanly. This is the predecessor to the current PR.

PR #25672 - #25672 (fix: prevent pkill hang when close event never fires)

  • Reason: Related but different issue - addresses a similar problem where the close event doesn't fire, causing hangs. While not an exact duplicate, it's addressing the same underlying Windows child process issue pattern.

On Windows, when a child process spawns grandchild processes (e.g., build
tools like hvigor/Gradle daemons), the grandchild may inherit the stdout/stderr
pipe handles. Even after the direct child exits, these inherited handles keep
the pipe open, preventing Node.js 'close' event from firing.

Since exitCode was resolved only on 'close', this caused bash tool to hang
indefinitely in Effect.raceAll waiting for handle.exitCode.

Fix: resolve exitCode on 'exit' event with a 2-second fallback. If 'close'
fires within 2 seconds (normal case), behavior is unchanged. If 'close' does
not fire (daemon holds pipe handle), fallback resolves after 2 seconds.

Closes anomalyco#24784
@bingkxu bingkxu force-pushed the fix/windows-childprocess-close-hang branch from 0f1e6c6 to a3c16fd Compare May 7, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: bash tool hangs on Windows when grandchild process inherits stdout pipe

1 participant