INNER CODE UNIT · TypeScript
shutdown
lidge-jun/opencodex · src/cli/index.ts:699
const shutdown = (signal?: NodeJS.Signals) => {
const now = Date.now();
if (shuttingDown) {
if (now - shutdownStartedAt < FORCE_AFTER_MS) return; // near-simultaneous duplicate — ignore
console.log("\n⏹ Force shutdown (second signal).");
try { syncCleanup(); } catch { /* best-effort */ }
process.exit(130);
}
shuttingDown = true;
shutdownStartedAt = now;
noteExplicitShutdownRequested(); // an automatic package restart must not hand off after this
console.log("\n🛑 Shutting down opencodex proxy...");
void (async () => {
let shutdownSucceeded = false;
try {
shutdownSucceeded = await drainAndShutdown(server, config.shutdownTimeoutMs ?? 5000, () => { syncCleanup(); return undefined; });
} finally {
const restored = syncCleanup(); // idempotent (cleaned-guard); also re-run by process.on("exit")