From 685e864d6218d5b83123fbb843e3ab05c0681fb3 Mon Sep 17 00:00:00 2001 From: Tiago Neves Date: Thu, 15 Oct 2026 06:25:31 +0100 Subject: [PATCH] fix(api): swallow EPIPE on dead worker stdin write (BIT-31194) 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 --- apps/api/src/lib/line-process.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/api/src/lib/line-process.ts b/apps/api/src/lib/line-process.ts index 7ff3a12..09650c2 100644 --- a/apps/api/src/lib/line-process.ts +++ b/apps/api/src/lib/line-process.ts @@ -21,6 +21,10 @@ export class LineProcess { if (this.ready) return this.ready; const child = spawn(this.opts.bin, this.opts.args ?? [], { stdio: ["pipe", "pipe", "pipe"] }); this.child = child; + // Writing to stdin after the child has died (e.g. mid-request crash) raises EPIPE; without + // this listener the unhandled "error" event on the stream kills the whole Node process. + // The "exit" handler below still rejects any pending requests. + child.stdin.on("error", () => {}); let stderr = ""; child.stderr.on("data", (d: Buffer) => { stderr = (stderr + d.toString()).slice(-2000); -- 2.47.3