Menu

Graceful Shutdown in Node.js and NestJS on Docker: SIGTERM, Draining, and Hook Order — Field Notes
📰

Graceful Shutdown in Node.js and NestJS on Docker: SIGTERM, Draining, and Hook Order — Field Notes

DEV Community: docker·Ahmed Mahmoud·about 9 hours ago
#sZXWkCV2
#devtodocker#devto#dev#node#process
Reading 0:00
15s threshold

Headline: A graceful shutdown means a Node.js process that receives SIGTERM stops taking new work, finishes what is in flight, closes its database and Redis connections, and exits before the orchestrator's grace period ends. In a Dockerized NestJS app that takes an exec-form CMD , app.enableShutdownHooks() , and cleanup placed in the lifecycle hook that runs after the HTTP server drains.

Redeploying my containerized NestJS APIs used to cost a handful of 502s and, now and then, a queue job that ran twice. The logs showed no errors. The clue was in docker ps -a : the old containers ended with Exited (137) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.