Skip to content

Commit 30ae4ca

Browse files
fix(cli): npm launcher no longer leaves a runtime running after a stop signal
The npm launcher forwarded SIGTERM/SIGHUP (and SIGINT under IPC) to the runtime and then waited for it forever. A runtime that could not finish shutting down kept the launcher alive until launchd SIGKILLed the launcher, orphaning the runtime. After forwarding a stop signal, the launcher now SIGKILLs the runtime if it has not exited within 5 s, matching the `t3 service` launcher's terminateChild grace. Fixes #30435 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e4345de commit 30ae4ca

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎scripts/npm-launcher/t3.mjs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const { version } = JSON.parse(
1111
);
1212

1313
const SUPPORTED = ["darwin-arm64", "linux-arm64", "linux-x64", "win32-arm64", "win32-x64"];
14+
// Well inside launchd's 20 s ExitTimeOut, which SIGKILLs only the launcher and orphans the runtime.
15+
const TERMINATE_GRACE_MS = 5_000;
1416

1517
function t3Home() {
1618
const raw = (process.env.T3CODE_HOME || "").trim();
@@ -169,8 +171,13 @@ async function main() {
169171
child.on("message", (message) => process.connected && process.send(message));
170172
process.on("disconnect", () => child.connected && child.disconnect());
171173
}
174+
let force;
172175
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
173-
process.on(signal, () => (ipc || signal !== "SIGINT") && child.kill(signal));
176+
process.on(signal, () => {
177+
if (!ipc && signal === "SIGINT") return;
178+
child.kill(signal);
179+
force ??= setTimeout(() => child.kill("SIGKILL"), TERMINATE_GRACE_MS).unref();
180+
});
174181
}
175182
child.on("error", (error) => fail(error));
176183
child.on("exit", (code, signal) =>

0 commit comments

Comments
 (0)