fix: #3865 ensure pm2 never run simultaneous gracefullExit, prevent dump file corruption

This commit is contained in:
vince 2018-08-21 16:01:49 +02:00
parent e868f003e3
commit 79679db1b3

View File

@ -331,6 +331,12 @@ Daemon.prototype.sendReady = function(cb) {
Daemon.prototype.gracefullExit = function() {
var that = this;
// never execute multiple gracefullExit simultaneously
// this can lead to loss of some apps in dump file
if (this.isExiting) return
this.isExiting = true
God.bus.emit('pm2:kill', {
status : 'killed',
msg : 'pm2 has been killed by SIGNAL'
@ -352,6 +358,7 @@ Daemon.prototype.gracefullExit = function() {
fs.unlinkSync(that.pid_path);
} catch(e) {}
setTimeout(function() {
that.isExiting = false
console.log('Exited peacefully');
process.exit(cst.SUCCESS_EXIT);
}, 2);