RafalWilinski / express-status-monitor

🚀 Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev
https://dynobase.dev/
MIT License
3.6k stars 257 forks source link

How to graceful shutdown #202

Open ipratico opened 1 year ago

ipratico commented 1 year ago

Hello, I'm using a graceful shutdown to close my express server:

process.on('SIGINT', function(){
   server.close(function(err) {
       process.exit(err ? 1 : 0);
   });
}); 

server.close() stops the server from accepting new connections and call the function after all the existing connections are finished. If someone has the page /status open the server won't close because the socket is still open and stays open until the page is closed.

Is there a way to force disconnect all the sockets connected? I know that socket.io provides this function: io.disconnectSockets(), but how can I access to the "io" instance of express-status-monitor?

devr77 commented 1 year ago

If You are In Production, I Will recommend use pm2.

dchitwood3 commented 1 year ago

I'm interested in this as well. We run express.js in our Puppeteer testing. Once the test is complete, we need to gracefully exit express.js. However, express-status-monitor is blocking this.