Graceful shutdown helper that drains in‑flight requests and cleans up resources on SIGTERM/SIGINT.
// Source: https://github.com/b3nw/omniroute-slim | License: MIT | Copyright 2026 diegosouzapw
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Graceful Shutdown — E-2 Critical Fix
*
* Handles SIGTERM / SIGINT to drain in-flight requests before exit.
* Critical for Docker containers and Kubernetes pods where hard kills
* can drop active SSE streams.
*
* Usage:
* import { initGracefulShutdown } from "@/lib/gracefulShutdown";
* initGracefulShutdown();
*
* @module lib/gracefulShutdown
*/
import { markServerStopping } from "@/lib/serverLifecycle";
/** Grace period before forced exit (default 30s, configurable) */
const SHUTDOWN_TIMEOUT_MS = parseInt(process.env.SHUTDOWN_TIMEOUT_MS || "30000", 10);
declare global {
var __omnirouteShutdown:
{ init:
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key