I've come across a problem on one of my Nodejs apps running with npm start
(which just does node app.js
).
My app contains a sigint handler as follows:
process.on('SIGINT', () => {
db.disconnect().then({
process.exit(0);
}).catch(e => process.exit(1));
});
With corresponding logs. After some testing on other files, I've noticed that Ctrl-C when on an npm
process triggers SIGINT twice if the first one takes too long to exit. (try adding a timeout on a sample app).
For now I've added a counter to check if the call is performed more than once, but I'm not sure that's "the way to go" concerning this issue. I'm guessing that a SIGINT on an npm process is expected to quit in a certain timeframe, which is why npm passes it on one more time (always only twice).
Has anyone come across this problem and found a viable solution?
Thanks!