From cc07d5c4f84ccd05d1ce94d3ef7b91122f2c8079 Mon Sep 17 00:00:00 2001 From: Michael Yong Date: Thu, 20 Aug 2026 11:19:57 -0700 Subject: [PATCH] Register start-bb signal handlers before spawning --- scripts/start-bb.mjs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/start-bb.mjs b/scripts/start-bb.mjs index 4c6e0f2be0..3d354e50bc 100644 --- a/scripts/start-bb.mjs +++ b/scripts/start-bb.mjs @@ -26,12 +26,7 @@ function waitForProcess(child) { } export async function runBuildProcess(request) { - const child = spawn(request.command, request.args, { - cwd: request.cwd, - detached: supportsProcessGroups(), - env: request.env, - stdio: "inherit", - }); + let child; let stopPromise; const stopChild = () => { stopPromise ??= stopProcessGroupLeaderFirst({ @@ -42,10 +37,18 @@ export async function runBuildProcess(request) { }; const handleSigint = () => stopChild(); const handleSigterm = () => stopChild(); + // Register before spawn so a child that becomes ready immediately cannot + // prompt another process to signal us before the handlers exist. process.on("SIGINT", handleSigint); process.on("SIGTERM", handleSigterm); try { + child = spawn(request.command, request.args, { + cwd: request.cwd, + detached: supportsProcessGroups(), + env: request.env, + stdio: "inherit", + }); const result = await waitForProcess(child); await stopPromise; return result;