fix(daemon): handle startup stderr errors

This commit is contained in:
Brennan Benson
2026-08-27 16:25:31 -07:00
parent a6c46ff241
commit 1087bad8da
2 changed files with 11 additions and 1 deletions
@@ -86,6 +86,16 @@ describe('observeDaemonChildExit', () => {
expect(onExit).toHaveBeenCalledOnce()
})
it('swallows stderr errors before readiness', () => {
const child = createChild()
const onExit = vi.fn()
const observer = observeDaemonChildExit(child, onExit)
expect(() => child.stderr.emit('error', new Error('startup pipe error'))).not.toThrow()
expect(onExit).not.toHaveBeenCalled()
observer.stop()
})
it('does not infer an exit from stderr or contact loss', () => {
const child = createChild()
const onExit = vi.fn()
@@ -101,6 +101,7 @@ export function observeDaemonChildExit(
}
child.stderr?.on('data', onStderr)
child.stderr?.on('error', onStderrError)
child.stderr?.on('end', onStderrEnd)
child.stderr?.on('close', onStderrEnd)
@@ -113,7 +114,6 @@ export function observeDaemonChildExit(
return
}
ready = true
child.stderr?.on('error', onStderrError)
child.stderr?.unref?.()
child.on('exit', onProcessExit)
},