From caa8543b2b15679a35f4e14d59f2cc6f088b0930 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Sun, 21 Jun 2026 08:36:22 +0000 Subject: [PATCH] fix(server): make the analyze worker's IPC send() failure-safe (#2264 review P3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The worker's send() used `process.send?.(msg)` — the `?.` guards an undefined channel but not a throw from an already-closed one (ERR_IPC_CHANNEL_CLOSED). A throw in the catch-branch send() would escape the message handler and skip the scheduled `setTimeout(process.exit(0))`, stranding the worker (with skip-close leaving native handles open, #2264). Wrap process.send in try/catch so the exit always fires; a vanished child is a failure to the parent regardless. Not unit-tested: send() is module-private and importing the worker registers process signal handlers; the change is a defensive try/catch around one call. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01JBJomjoTdBV2eveDVq4JMm --- gitnexus/src/server/analyze-worker.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitnexus/src/server/analyze-worker.ts b/gitnexus/src/server/analyze-worker.ts index fb00b6502..b00c66acf 100644 --- a/gitnexus/src/server/analyze-worker.ts +++ b/gitnexus/src/server/analyze-worker.ts @@ -44,7 +44,14 @@ export interface ErrorMessage { export type WorkerMessage = ProgressMessage | CompleteMessage | ErrorMessage; function send(msg: WorkerMessage) { - process.send?.(msg); + try { + process.send?.(msg); + } catch { + // The parent may have already disconnected the IPC channel + // (ERR_IPC_CHANNEL_CLOSED). Swallow so a failed notification can't escape the + // message/SIGTERM handlers and skip their scheduled process.exit (#2264 review + // P3) — a vanished child is treated as a failure by the parent regardless. + } } // Catch uncaught exceptions and unhandled rejections — report to parent