Backend process handles graceful shutdown
Why it matters
A backend process that ignores SIGTERM drops in-flight requests immediately when the orchestrator (Kubernetes, Railway, Fly.io, Heroku) restarts or redeploys it. Users mid-checkout, mid-upload, or mid-auth flow receive hard errors with no recovery path. CWE-460 (improper cleanup on thrown exception) encompasses improper shutdown handling. Platforms send SIGTERM and wait a grace period (typically 30 seconds) before SIGKILL; failing to handle it means every deploy causes unannounced request failures that are invisible in your error tracking.
Severity rationale
Low in environments with short-lived requests, but causes guaranteed data loss and user-facing errors on every deployment in applications with long-running operations.
Remediation
Register SIGTERM and SIGINT handlers in your server entry point. Stop accepting new connections immediately, let in-flight requests finish, then close the database pool and exit.
// src/server.ts
const server = app.listen(3000)
async function shutdown(signal: string) {
console.log(`${signal} received — shutting down`)
server.close(async () => {
await pool.end()
process.exit(0)
})
// Force exit if drain takes too long
setTimeout(() => process.exit(1), 30_000)
}
process.on('SIGTERM', () => shutdown('SIGTERM'))
process.on('SIGINT', () => shutdown('SIGINT'))
Test graceful shutdown locally: run your server, send kill -SIGTERM <pid>, and verify in-flight requests complete before the process exits.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Error Resilience Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-460 — Improper Cleanup on Thrown Exception
- iso-25010:2011 · reliability.recoverability
- soc2:2017 · A1.2 — Environmental protections, backup, and recovery infrastructure
Taxons
History
- 2026-04-18·v1.0.0·Initial import from error-resilience·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (A1.2) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2