fix(api): swallow EPIPE on dead worker stdin write (BIT-31194) #3

Merged
spark merged 1 commits from fix/BIT-31194-line-process-epipe into main 2026-10-15 06:26:47 +01:00
Owner

Fixes BIT-31194 — Error Loop crash: write EPIPE at apps/api/src/lib/line-process.ts:80.

LineProcess.request() writes JSON requests to the worker child process stdin. When the worker dies mid-request, the write can race the exit handler and hit the pipe after it already broke, raising EPIPE. With no error listener on child.stdin, that was an unhandled stream error that crashed the whole API process.

Fix: attach a no-op error listener on child.stdin right after spawn. The existing exit handler already rejects any pending requests for that worker, so callers still get a clean rejection instead of a process crash.

Verified with a standalone repro (200 rapid spawn+write races against short-lived children): crashes reliably with write EPIPE without the listener, survives cleanly with it. tsc --noEmit shows no new errors (38 pre-existing unrelated errors on main, none in this file).

Fixes BIT-31194 — Error Loop crash: `write EPIPE` at `apps/api/src/lib/line-process.ts:80`. `LineProcess.request()` writes JSON requests to the worker child process stdin. When the worker dies mid-request, the write can race the `exit` handler and hit the pipe after it already broke, raising EPIPE. With no `error` listener on `child.stdin`, that was an unhandled stream error that crashed the whole API process. Fix: attach a no-op `error` listener on `child.stdin` right after spawn. The existing `exit` handler already rejects any pending requests for that worker, so callers still get a clean rejection instead of a process crash. Verified with a standalone repro (200 rapid spawn+write races against short-lived children): crashes reliably with `write EPIPE` without the listener, survives cleanly with it. `tsc --noEmit` shows no new errors (38 pre-existing unrelated errors on main, none in this file).
spark added 1 commit 2026-10-15 06:26:19 +01:00
fix(api): swallow EPIPE on dead worker stdin write (BIT-31194)
ci / rust (pull_request) Successful in 9m6s
ci / typescript (pull_request) Successful in 11m34s
685e864d62
LineProcess.request() writes JSON requests to the worker child process stdin
(line-process.ts:80). When the worker dies mid-request the write can race the
exit handler and hit the pipe after it's already broken, raising EPIPE. With
no "error" listener on child.stdin, that EPIPE was an unhandled stream error
and crashed the whole API process. Attach a no-op error listener on stdin;
the existing "exit" handler already rejects any pending requests for that
worker, so callers still see a clean rejection instead of a process crash.

Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-31194
Paperclip-Run: de3027ac-866e-4c9d-919b-6f21ff532c3d
spark scheduled this pull request to auto merge when all checks succeed 2026-10-15 06:26:46 +01:00
spark merged commit 0736d34f4d into main 2026-10-15 06:26:47 +01:00
spark deleted branch fix/BIT-31194-line-process-epipe 2026-10-15 06:26:48 +01:00
Sign in to join this conversation.