Skip to content

Commit a723a21

Browse files
committed
fix(infra): attach error listener to detached spawn to prevent unhandled rejection crash
spawnDetachedGatewayProcess calls child.unref() without attaching an error listener. If spawn fails asynchronously (ENOMEM, missing executable), the ChildProcess emits an unhandled 'error' event that crashes the parent Node process. Add a guard-checked noop error listener before unref() to prevent the unhandled-event crash. Fixes #101458
1 parent 82b0f7c commit a723a21

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/infra/process-respawn.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ function spawnDetachedGatewayProcess(opts: GatewayRespawnOptions = {}): {
5353
detached: true,
5454
stdio: "inherit",
5555
});
56+
// Attach a noop error listener before unref so async spawn failures
57+
// (ENOMEM, missing executable, etc.) don't crash the parent as an
58+
// unhandled 'error' event on the ChildProcess.
59+
if (typeof child.on === "function") {
60+
child.on("error", () => {});
61+
}
5662
child.unref();
5763
return { child, pid: child.pid ?? undefined };
5864
}

0 commit comments

Comments
 (0)