Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/src/cross-spawn-spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ export const make = Effect.gen(function* () {
})
proc.on("exit", (...args) => {
exit = args
setTimeout(() => {
if (!end) {
end = true
Deferred.doneUnsafe(signal, Exit.succeed(args))
}
}, 2000)
})
proc.on("close", (...args) => {
if (end) return
Expand Down
30 changes: 30 additions & 0 deletions packages/core/test/effect/cross-spawn-spawner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ describe("cross-spawn spawner", () => {
expect(running).toBe(false)
}),
)

fx.effect(
"exit fallback resolves when close hangs due to grandchild holding pipe",
Effect.gen(function* () {
// Windows-specific: grandchild inheriting stdout pipe can block close event
if (process.platform !== "win32") return

// Spawn child that creates grandchild inheriting stdout and running 10s.
// Child exits immediately; grandchild holds pipe, preventing close event.
// Expected: exitCode resolves after ~2s fallback, not hangs indefinitely.
const started = Date.now()
const handle = yield* js(`
const { spawn } = require('child_process')
spawn(process.execPath, ['-e', 'setTimeout(()=>{}, 10000)'], {
stdio: ['ignore', process.stdout, 'ignore'],
detached: true
})
process.exit(0)
`)
const code = yield* handle.exitCode
const elapsed = Date.now() - started

// Fallback timeout = 2000ms in cross-spawn-spawner.ts spawn function.
// - Lower bound 1500ms: ensures fallback was triggered (not close firing early)
// - Upper bound 5000ms: allows for child spawn overhead + system load variance
expect(elapsed).toBeGreaterThan(1500)
expect(elapsed).toBeLessThan(5000)
expect(code).toBe(ChildProcessSpawner.ExitCode(0))
}),
)
})

describe("error handling", () => {
Expand Down
Loading