implement-graceful-shutdown
Installation
SKILL.md
Summary
Backend services must listen for OS signals (like SIGTERM and SIGINT) and perform a Graceful Shutdown procedure. This ensures that no in-flight requests are dropped abruptly during deployments or scaling events.
Rationale
- Zero Downtime: Rolling updates in Kubernetes or other orchestrators rely on the application handling
SIGTERMto safely drain traffic. - Data Integrity: Ensures database transactions and open file handles are closed properly, not corrupted by a forced kill.
Guidance
- Listen: Use
signal.Notify(Go) orprocess.on('SIGTERM')(Node.js) to catch signals. - Stop: Stop the HTTP server from accepting new connections.
- Wait: Allow existing requests a timeout window (e.g., 5-30 seconds) to complete.
- Close: Close database connections, cache connections, and other resources.
- Exit: Exit the process with code 0.