graceful-shutdown by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill graceful-shutdown实现正确的关闭流程,确保在进程终止前完成所有请求、关闭连接并释放资源。
最小工作示例:
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();
}
private setupMiddleware(): void {
// Track active connections
this.app.use((req, res, next) => {
if (this.isShuttingDown) {
res.set("Connection", "close");
return res.status(503).json({
error: "Server is shutting down",
// ... (完整实现请参阅参考指南)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
| 指南 | 内容 |
|---|---|
| Express.js 优雅停机 | Express.js 优雅停机 |
| Kubernetes 感知的停机 | Kubernetes 感知的停机 |
| 工作进程停机 | 工作进程停机 |
| 数据库连接池停机 | 数据库连接池停机 |
| PM2 优雅停机 | PM2 优雅停机 |
| Python/Flask 优雅停机 | Python/Flask 优雅停机 |
每周安装数
103
代码仓库
GitHub 星标数
121
首次出现
2026年1月21日
安全审计
安装于
opencode86
gemini-cli84
codex83
claude-code80
cursor79
github-copilot69
Implement proper shutdown procedures to ensure all requests are completed, connections are closed, and resources are released before process termination.
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();
}
private setupMiddleware(): void {
// Track active connections
this.app.use((req, res, next) => {
if (this.isShuttingDown) {
res.set("Connection", "close");
return res.status(503).json({
error: "Server is shutting down",
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Express.js Graceful Shutdown | Express.js Graceful Shutdown |
| Kubernetes-Aware Shutdown | Kubernetes-Aware Shutdown |
| Worker Process Shutdown | Worker Process Shutdown |
| Database Connection Pool Shutdown | Database Connection Pool Shutdown |
| PM2 Graceful Shutdown | PM2 Graceful Shutdown |
| Python/Flask Graceful Shutdown | Python/Flask Graceful Shutdown |
Weekly Installs
103
Repository
GitHub Stars
121
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode86
gemini-cli84
codex83
claude-code80
cursor79
github-copilot69
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
96,200 周安装
游戏架构模式:构建结构良好的浏览器游戏(Three.js/Phaser)核心原则与最佳实践
105 周安装
Web Audio API 游戏音频工程师指南 - 程序化生成BGM与音效,零依赖
105 周安装
Bruno集合生成器 - 自动为开源API客户端生成Git友好的Bruno集合文件
105 周安装
Git Commit 自动化工具:智能分析代码变更,生成规范提交信息,提升开发效率
105 周安装
PostgreSQL/MySQL数据库模式设计指南:规范化、约束与最佳实践
105 周安装
Helius Solana开发指南:RPC API、实时数据流与区块链工具集成
105 周安装