From 8c3a45d035a7f397b887270a1173928640d46de5 Mon Sep 17 00:00:00 2001 From: kagura-agent Date: Mon, 20 Jul 2026 10:05:42 +0800 Subject: [PATCH] fix(desktop): handle async EPIPE on process.stderr process.stderr can emit async 'error' events with EPIPE that bypass the existing synchronous try-catch in initConsoleTransport(). This causes uncaught exception crashes when the parent terminal is closed while the desktop app is still running. Add a listener on process.stderr that catches EPIPE errors and disables the console transport, matching the existing synchronous EPIPE guard pattern. The listener self-removes after the first EPIPE to avoid stale references. Closes #37749 --- packages/desktop/src/main/logging.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/desktop/src/main/logging.ts b/packages/desktop/src/main/logging.ts index 8866fd78ef77..146c32601f19 100644 --- a/packages/desktop/src/main/logging.ts +++ b/packages/desktop/src/main/logging.ts @@ -198,6 +198,13 @@ function initConsoleTransport() { log.transports.console.level = false } } + + const onStderrError = (err: Error) => { + if (!isBrokenPipe(err)) return + log.transports.console.level = false + process.stderr.removeListener("error", onStderrError) + } + process.stderr.on("error", onStderrError) } function isBrokenPipe(err: unknown) {