Skip to main content

Graceful Shutdown

Shutdown Sequence

Signal received (SIGTERM or SIGINT)
|
+-- 1. Stop accepting new HTTP connections (listener.Close)
|
+-- 2. Wait for in-flight HTTP requests to complete (30s timeout)
| +-- If timeout: force-close remaining connections, log warning
|
+-- 3. Shutdown loaded engine plugins
| +-- Call Shutdown() on each loaded engine (5s timeout per engine)
|
+-- 4. Stop the reaper goroutine
|
+-- 5. Flush pending audit events
| +-- Drain the dispatcher queue (10s timeout)
|
+-- 6. Close database connections
| +-- SQLite: checkpoint WAL, close
| +-- PostgreSQL: close connection pool
|
+-- 7. Exit 0

Rules

  • Total timeout: 60 seconds. After that, os.Exit(1).
  • Logging: Log each step: "shutting down: waiting for in-flight requests...", "shutting down: stopping plugins..."
  • Double signal: A second SIGTERM/SIGINT during shutdown triggers an immediate exit (for stuck processes).