Skip to content

fix(desktop): handle async EPIPE on process.stderr#37834

Open
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/desktop-stderr-epipe-crash
Open

fix(desktop): handle async EPIPE on process.stderr#37834
kagura-agent wants to merge 1 commit into
anomalyco:devfrom
kagura-agent:fix/desktop-stderr-epipe-crash

Conversation

@kagura-agent

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #37749

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The desktop app crashes with an uncaught EPIPE when the parent terminal is closed while the app is still running. The existing initConsoleTransport() wraps writeFn in a synchronous try-catch, but process.stderr can also emit async 'error' events with EPIPE that bypass this guard.

This adds a process.stderr.on("error", ...) listener that:

  1. Checks if the error is EPIPE using the existing isBrokenPipe() helper
  2. If EPIPE: disables the console transport (log.transports.console.level = false) and removes itself
  3. If not EPIPE: returns without handling (lets the error propagate normally)

This extends the same pattern already used for the synchronous path — isBrokenPipe() check + transport disable.

How did you verify your code works?

  • Confirmed the change is a 7-line additive-only diff touching one file
  • Typecheck passes (all errors are pre-existing in unrelated packages)
  • No existing test file for this module (Electron main process context required)
  • Structural review confirms the listener follows the exact same pattern as the synchronous guard above it

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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 anomalyco#37749
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(desktop): async EPIPE on process.stderr bypasses console transport try-catch

1 participant