From 1087bad8daffaa131fc4bb503663e6eaaa2c0c25 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:25:31 -0700 Subject: [PATCH] fix(daemon): handle startup stderr errors --- src/main/daemon/daemon-child-exit-observer.test.ts | 10 ++++++++++ src/main/daemon/daemon-child-exit-observer.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/daemon/daemon-child-exit-observer.test.ts b/src/main/daemon/daemon-child-exit-observer.test.ts index af9e4c61c3f..69936500b86 100644 --- a/src/main/daemon/daemon-child-exit-observer.test.ts +++ b/src/main/daemon/daemon-child-exit-observer.test.ts @@ -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() diff --git a/src/main/daemon/daemon-child-exit-observer.ts b/src/main/daemon/daemon-child-exit-observer.ts index 7a59d55809c..c22ec0ce1db 100644 --- a/src/main/daemon/daemon-child-exit-observer.ts +++ b/src/main/daemon/daemon-child-exit-observer.ts @@ -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) },