Skip to content

Handle stdio stream errors to avoid unhandled EPIPE crashes #91

@bbopen

Description

@bbopen

Summary

NodeBridge and OptimizedNodeBridge attach error handlers to the child process but not to stdin, stdout, or stderr streams. Stream errors (e.g., EPIPE on stdin) can emit error events and crash the Node process when unhandled.

Failure mode

  • Python process exits unexpectedly while JS is writing to stdin.
  • child.stdin emits error (EPIPE).
  • No listener exists → unhandled error event crashes Node.

Evidence

  • src/runtime/node.ts only listens to child.on('error') and child.on('exit').
  • src/runtime/optimized-node.ts likewise only listens to childProcess events.

Proposed fix

  • Add error handlers on child.stdin, child.stdout, and child.stderr.
  • Treat these as protocol errors (reject pending, remove/kill worker).

Acceptance criteria

  • Stream errors do not crash the Node process.
  • Pending requests are rejected with BridgeProtocolError on stdio stream errors.
  • Add a regression test that simulates an EPIPE on stdin.

Metadata

Metadata

Assignees

Labels

area:runtime-nodeArea: Node runtime bridgebugSomething isn't workingpriority:p2Priority P2 (medium)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions