/dstack-typescript:nodejs-graceful-shutdownfrom DStack TypeScript
Implements graceful shutdown for Node.js servers: handles SIGTERM/SIGINT, drains connections, signals health-check 503, and closes external dependencies within a configurable timeout.
Ships in DStack TypeScript. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You make a Node.js server stop without dropping work. When the process gets SIGTERM or SIGINT (a deploy, a scaler, a Ctrl-C), it stops accepting new connections, tells the load balancer it is going away, lets in-flight requests finish inside a deadline, closes its database and queue handles, and exits with a code that says whether the drain was clean. If the ask is really about scaffolding the whole service (env, logging, errors), that belongs to nodejs-service-foundations instead.
This stays local and reversible: you edit only the server shutdown handler and add one companion test, both rolled back through version control. You never touch remote state. The only runtime side effect is starting a short-lived server to watch it drain.
What you need before starting:
SOURCES: files under $CWD/src or $CWD/lib holding the http.createServer or Express/Fastify listen bootstrap (one file is fine). Required.SERVER_PORT: TCP port the test server binds. Required.HEALTH_ROUTE: health or readiness path. Required.DRAIN_TIMEOUT_MS: milliseconds to wait for in-flight requests before forcing the exit. Required, positive integer, default 10000.EXTERNAL_DEPENDENCIES: every external handle the app opens (database pools, Redis clients, queue producers). Required, may be empty.Read every file in SOURCES and find the bootstrap: the listen call and the variable holding the server instance. Keep any existing named process.on handler and update it rather than registering a second handler on the same signal. Both SIGTERM and SIGINT must end at a single shutdown function, guarded by module-scope state declared as let isShuttingDown = false. If that flag does not exist yet, add it.
The first thing shutdown does is set isShuttingDown = true, and the health endpoint reads that flag on every request: 200 OK with {"status":"ok"} while serving, 503 Service Unavailable with {"status":"shutting_down"} once draining starts. This flip must land before server.close() runs, so a health probe sent right after the signal reliably sees the 503 while the server is still up.
After the health flip, call server.close() on the real server instance and await it (never a fixed sleep), raced against a DRAIN_TIMEOUT_MS timeout. If close resolves first the drain was graceful; if the timer wins, requests are still in flight and the exit must be non-zero. Then close every entry in EXTERNAL_DEPENDENCIES:
pool.end()redis.quit()producer.disconnect()Leave OS-level sockets alone. Await every close; an unresponsive dependency gets recorded, not retried forever. Partial cleanup (some handles closed, others not) counts as failure.
Exit 0 only when the server drained inside the deadline and every dependency closed. Exit 1 when the drain timed out or any dependency stayed unresponsive, so callers can tell a clean drain from a forced one.
Write <filename>.test.ts next to the handler and run it with node --test or the project's runner until it is green. The test spawns the server with DRAIN_TIMEOUT_MS=500, then:
GET /<HEALTH_ROUTE> and expects 200SIGTERM503 with shutting_down0 when the long request finished inside the deadlineAll of those assertions must exist and pass.
closeExternalConnections(): record which one, give each dependency close its own timeout, and exit 1. The companion test sees the non-zero code.DRAIN_TIMEOUT_MS: the timeout wins the race against server.close(). Exit 1, and either raise the timeout or stop the service holding connections past it.1. The usual cause is a handle missing from EXTERNAL_DEPENDENCIES, so add it.isShuttingDown guard before the I/O call, not after.server.close().Edited shutdown code plus a passing companion test, demonstrating the 503 health flip ahead of server.close(), a clean drain inside the deadline, and an exit code that separates graceful shutdown from deadline-forced termination.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gosuda/dstack-skills --plugin dstack-typescript5 skills in this plugin
/node-internals-diagnosisUse when Node.js segfaults, addon crashes, leaks, event-loop anomalies, thread-pool saturation, V8 deoptimizations, or binding.gyp failures need diagnosis. Not for code edits or service restarts./nodejs-service-foundationsUse when asked to set up or harden Node.js service foundations: env validation, logging, typed errors, type stripping, and shutdown wiring. Not for dedicated shutdown: use nodejs-graceful-shutdown./typescript-best-practicesUse when TypeScript needs shaping toward narrow types, unions, exhaustive variants, and strict flags. Not for error repair: use typescript-type-hardening. Not for non-TS domains: use type-driven.Other plugins' skills for the same job