Skip to content

Commit 2295914

Browse files
fix(opencode): use exit event instead of close to resolve bash tool hang
When a bash command spawns a background child process (e.g. `npm run build &`), the shell exits immediately but Node's `close` event won't fire until the background process also closes its inherited stdout/stderr pipe descriptors. This causes the bash tool to hang indefinitely (until the 2-minute timeout). Fix: resolve the spawn promise on the `exit` event instead of `close`. The `exit` event fires as soon as the spawned process terminates, regardless of inherited pipe descriptors. Fixes anomalyco#20902
1 parent f39b9c0 commit 2295914

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎packages/opencode/src/effect/cross-spawn-spawner.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,10 @@ export const make = Effect.gen(function* () {
272272
resume(Effect.fail(toPlatformError("spawn", err, command)))
273273
})
274274
proc.on("exit", (...args) => {
275-
exit = args
276-
})
277-
proc.on("close", (...args) => {
278275
if (end) return
279276
end = true
280-
Deferred.doneUnsafe(signal, Exit.succeed(exit ?? args))
277+
exit = args
278+
Deferred.doneUnsafe(signal, Exit.succeed(exit))
281279
})
282280
proc.on("spawn", () => {
283281
resume(Effect.succeed([proc, signal]))

0 commit comments

Comments
 (0)