
Graceful Shutdown
This handles the unsexy but critical work of shutting down your application without dropping requests or leaking resources. It covers the full stack: tracking active connections, rejecting new requests during shutdown, waiting for in-flight work to finish, and cleaning up database pools and other resources. The guides show Express, Flask, PM2, and Kubernetes setups, which is the right mix since shutdown logic varies enough between environments that you can't just copy-paste. The 30-second default timeout is reasonable but you'll want to tune it based on your actual request durations. Worth implementing before your first production incident, not after.
- skills.sh installs
- 439
- GitHub stars
- 379
- last updated
- Aug 21, 2026
Install
$ npx -y skills add aj-geddes/useful-ai-prompts --skill graceful-shutdown --agent claude-codeInstalls into .claude/skills of the current project.
Files
Graceful Shutdown
Table of Contents
Overview
Implement proper shutdown procedures to ensure all requests are completed, connections are closed, and resources are released before process termination.
When to Use
- Kubernetes/Docker deployments
- Rolling updates and deployments
- Server restarts
- Load balancer drain periods
- Zero-downtime deployments
- Process managers (PM2, systemd)
- Long-running background jobs
- Database connection cleanup
Quick Start
Minimal working example:
import express from "express";
import http from "http";
class GracefulShutdownServer {
private app: express.Application;
private server: http.Server;
private isShuttingDown = false;
private activeConnections = new Set<any>();
private shutdownTimeout = 30000; // 30 seconds
constructor() {
this.app = express();
this.server = http.createServer(this.app);
this.setupMiddleware();
this.setupRoutes();
this.setupShutdownHandlers();
}
Sponsors
Details
- Repository
- github.com/aj-geddes/useful-ai-prompts
- Categories
- Backend & APIs, AI & Agent Building
- First seen
- Jun 3, 2026
More from aj-geddes/useful-ai-prompts
All 258- Blue Green Deployment437
- Disaster Recovery Testing437
- Release Planning436
- Intermittent Issue Debugging433
- Server Side Rendering433
- Mocking Stubbing432
- Data Migration Scripts430
- Correlation Tracing429
- Synthetic Monitoring427
- Canary Deployment426
- Service Mesh Implementation426
- Azure Functions424
- Data Replication Setup424
- Graphql Implementation424
- Polyglot Integration424
- Distributed Tracing418
- Multi Cloud Strategy418
- Anomaly Detection
- Causal Inference
- Classification Modeling
- Clustering Analysis
- Cohort Analysis
- Computer Vision
- Correlation Analysis