Exit main process after too many exceptions

This commit is contained in:
Zaid Abdulla committed 2018-01-11 06:20:25 -08:00
1 parent 2f276c7ce2
commit 521907fa7d
2 files changed
+29 -5

No files matched your search

+28 -2
View File
@@ -24,6 +24,8 @@ const config = require("./config");
const VERSION = require("../package.json").version;
let respawnTimestamp = 0;
let tooManyCrashesTimestamp = 0;
function getDependencyVersions() {
let dependencies = [`node@${process.versions.node}`];
@@ -67,7 +69,32 @@ function restartWorker(worker, code, signal) {
msg.signal = signal;
logger.error(msg);
const now = Date.now();
respawnTimestamp = Math.max(now, respawnTimestamp + 2000);
if (respawnTimestamp === now) {
tooManyCrashesTimestamp = now;
cluster.fork();
return
}
if (now - tooManyCrashesTimestamp > 60000) {
process.exitCode = 1;
cluster.removeListener("exit", restartWorker);
for (let pid in cluster.workers)
cluster.workers[pid].kill();
logger.error({
message: "Too many crashes, exiting",
pid: process.pid
});
return;
}
setTimeout(function() {
if (process.exitCode) return;
cluster.fork();
}, respawnTimestamp - now);
}
@@ -140,11 +167,10 @@ process.on("uncaughtException", function(err) {
exception: err,
pid: process.pid
});
process.exitCode = 1;
cluster.removeListener("exit", restartWorker);
for (let pid in cluster.workers)
cluster.workers[pid].kill();
logger.close();
});
+1 -3
View File
@@ -70,13 +70,11 @@ exit = () ->
)
, 30000).unref()
cluster.worker?.disconnect()
closeServer(20000, () ->
db.disconnect()
cache.disconnect()
extensions.killAll()
logger.close()
cluster.worker?.disconnect()
)