From 79679db1b321bbcc7296dbc41d005500cf61d273 Mon Sep 17 00:00:00 2001 From: vince Date: Tue, 21 Aug 2018 16:01:49 +0200 Subject: [PATCH] fix: #3865 ensure pm2 never run simultaneous gracefullExit, prevent dump file corruption --- lib/Daemon.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Daemon.js b/lib/Daemon.js index f7ae6ba87..b6f9eb88f 100644 --- a/lib/Daemon.js +++ b/lib/Daemon.js @@ -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);