Skip to content

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

Closed
bingkxu wants to merge 1 commit into
anomalyco:devfrom
bingkxu:fix/windows-childprocess-close-hang
Closed

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

Conversation

@bingkxu

@bingkxu bingkxu commented May 7, 2026

Copy link
Copy Markdown

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

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

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
@jamhour1g

Copy link
Copy Markdown

3 weeks ago, and still not even reviewed?

@bingkxu

bingkxu commented Jun 2, 2026

Copy link
Copy Markdown
Author

Thanks for your patience. This PR is awaiting maintainer review — I've bumped it for attention. The fix addresses a Windows-specific child process hang issue that impacts reliability.

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@JBou

JBou commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Could this be re-opened?

According to this comment, this PR is the preferred solution.

@jamhour1g

Copy link
Copy Markdown

It's messed up that this issue, which still hasn’t been fixed, made me switch from OpenCode, and it’s funny how no one seems to care enough to even look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

3 participants