Standardise shutdown signal guarding

This commit is contained in:
Cooldude2606 committed 2026-04-14 22:10:01 +01:00
1 parent e9653c13eb
commit e8cabb7196
6 files changed
+37 -75

No files matched your search

+3 -16
View File
@@ -8,7 +8,6 @@ import fs from "node:fs/promises";
import yargs, { type Argv } from "yargs";
import path from "path";
import { version } from "./package.json";
import setBlocking from "set-blocking";
import { strict as assert } from "assert";
// Reduce startup time by lazy compiling schemas.
@@ -311,21 +310,9 @@ async function startControl() {
throw err;
}
let caughtSigInt = false;
process.on("SIGINT", () => {
if (caughtSigInt) {
logger.info("Caught second interrupt signal, forcing disconnect");
process.exit(1);
}
caughtSigInt = true;
logger.info("Caught interrupt signal, closing connection");
control.shutdown().catch(err => {
setBlocking(true);
logger.error(err.stack);
process.exit(1);
});
});
// Handle interrupts
process.on("SIGINT", lib.createShutdownGuard(logger, "interrupt", control.shutdown.bind(control)));
process.on("SIGTERM", lib.createShutdownGuard(logger, "termination", control.shutdown.bind(control)));
try {
const targetCommand = selectTargetCommand(args, rootCommands);