Deploying updates to a live production application without dropping a single active HTTP connection requires careful orchestration between the web server reverse proxy (Nginx) and process manager (PM2).
Graceful SIGINT Handling with PM2
When pm2 reload is called, PM2 spawns new application instances on new ports, waits for them to pass initial health checks, and then gracefully sends SIGINT to old workers allowing active HTTP requests to complete before termination.
javascript
// ecosystem.config.js
module.exports = {
apps: [{
name: 'serverlaas',
script: 'node_modules/next/dist/bin/next',
args: 'start',
instances: 'max',
exec_mode: 'cluster',
kill_timeout: 5000
}]
};