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-code

Installs 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
1hkuds avatarcli-anything-lldbhkuds/cli-anythingStateful LLDB debugging via LLDB Python API439skills.sh installs
2secondsky avatarpush-notification-setupsecondsky/claude-skillsImplements push notifications across iOS, Android, and web using Firebase Cloud Messaging and native services. Use when adding notification capabilities, handli436skills.sh installs
3solana-foundation avatarpaysolana-foundation/payUser-authorized paid HTTP/API access for agents through local Pay MCP and TouchID gated payments (x402 MPP HTTP 402) SERVICES: search web, scrape, enrich people436skills.sh installs
4pedronauck avatarcontext7pedronauck/skillsRetrieves authoritative, up-to-date technical documentation, API references, configuration details, and code examples for any developer technology. Use this ski435skills.sh installs
5maxnorm avatarmagento-performance-analystmaxnorm/magento2-agent-skillsConducts comprehensive Magento 2 performance analysis and optimization. Use when analyzing performance bottlenecks, profiling applications, optimizing database 434skills.sh installs
6pedronauck avatarelectron-builderpedronauck/skillsComprehensive guide for electron-builder (v26.x) packaging, code signing, auto-updates, and release workflows. Use when: (1) configuring electron-builder builds433skills.sh installs