Description
On Windows, when running build tools like hvigor/Gradle daemons through the bash tool, the command hangs indefinitely even after the child process exits.
Root Cause
When a child process spawns grandchild processes on Windows, the grandchild may inherit the stdout/stderr pipe handles. Even after the direct child exits (with exit code 0), these inherited handles keep the pipe open, preventing Node.js close event from firing.
In packages/core/src/cross-spawn-spawner.ts, the exitCode is resolved only when the close event fires. This causes Effect.raceAll to hang indefinitely waiting for handle.exitCode.
Reproduction
- Run a build command that spawns daemon processes (e.g., hvigorw assembleHap on HarmonyOS projects)
- Observe that bash tool hangs after the build completes
- The child process has exited but grandchild daemon still holds the pipe
Proposed Fix
Add a fallback in the exit event handler: if close does not fire within 2 seconds after exit, resolve exitCode using the exit event data. This matches the documented behavior difference between exit and close events in Node.js.
Environment
Platform: Windows
Node.js: v20+
OpenCode version: v1.14.x
Description
On Windows, when running build tools like hvigor/Gradle daemons through the bash tool, the command hangs indefinitely even after the child process exits.
Root Cause
When a child process spawns grandchild processes on Windows, the grandchild may inherit the stdout/stderr pipe handles. Even after the direct child exits (with exit code 0), these inherited handles keep the pipe open, preventing Node.js close event from firing.
In packages/core/src/cross-spawn-spawner.ts, the exitCode is resolved only when the close event fires. This causes Effect.raceAll to hang indefinitely waiting for handle.exitCode.
Reproduction
Proposed Fix
Add a fallback in the exit event handler: if close does not fire within 2 seconds after exit, resolve exitCode using the exit event data. This matches the documented behavior difference between exit and close events in Node.js.
Environment
Platform: Windows
Node.js: v20+
OpenCode version: v1.14.x