DEV Community

Cover image for Graceful shutdown NodeJS HTTP server when using PM2 (4/4)

Graceful shutdown NodeJS HTTP server when using PM2 (4/4)

Antonio Santiago on October 19, 2018

So you have created a NodeJS server that receives tons of requests and you are really happy but, as every piece of software, you found a bug or add...
Collapse
 
gajus profile image
Gajus Kuizinas

Calling server.close() is not enough – the server will hang until there are open connections. This could mean couple of seconds or hours. You need to track connections and terminate them one by one. Refer to my article about connection handling in Node.js dev.to/gajus/how-to-terminate-a-ht....

Collapse
 
acanimal profile image
Antonio Santiago

Awesome 🙌 !

Collapse
 
skiod profile image
Khalid Skiod

quick question sir, is there any tricks or params to wait until jobs to be finished then reload the server ??. i don't know when the jobs will be finished exactly and pm2 force us to use static param --timeout