From ad9bd9b6bec71334343a673cc946e023011c24a5 Mon Sep 17 00:00:00 2001 From: CorvusCorrax Date: Thu, 28 Dec 2017 10:34:00 +0100 Subject: [PATCH 1/2] Request error handler now correctly log errors --- lib/request.js | 2 ++ lib/requestErrorHandler.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/request.js b/lib/request.js index 18cf9c2..25d2ea3 100644 --- a/lib/request.js +++ b/lib/request.js @@ -224,6 +224,8 @@ module.exports = function(synapps) { } }; + req.log = synapps.debug; + // add debug message to log req.debug = function() { diff --git a/lib/requestErrorHandler.js b/lib/requestErrorHandler.js index 45e97c3..395039b 100644 --- a/lib/requestErrorHandler.js +++ b/lib/requestErrorHandler.js @@ -11,7 +11,7 @@ requestErrorHandler.prototype.run = function(fn) { var self = this; this.domain.on('error', function(err) { self.executionError = err; - self.req.debug(err); + self.req.log('error', err); self.req.reject("#INTERNAL_SERVER_ERROR"); }); this.domain.run(fn); From 8c71b918e1cc7d23429e38aae422b13b4fbea4ed Mon Sep 17 00:00:00 2001 From: CorvusCorrax Date: Thu, 28 Dec 2017 10:34:33 +0100 Subject: [PATCH 2/2] Reworked workers killing on master shutdown --- lib/scheduler.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/scheduler.js b/lib/scheduler.js index 2988a9d..6fa56ff 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -59,15 +59,23 @@ module.exports = function(synapps) { running = false; asynk.each(scheduler._workers, function(worker, cb) { process.kill(worker.pid, 'SIGTERM'); - setTimeout(function() { - try { - process.kill(worker.pid, 0); - process.kill(worker.pid, 'SIGKILL'); - cb(); - } catch(e) { - cb(); - } - }, 5000); + var iteration = 0; + var waitAndKill = function(callback) { + ++iteration; + setTimeout(function() { + try { + process.kill(worker.pid, 0); + if (iteration > 5) { + process.kill(worker.pid, 'SIGKILL'); + return callback(); + } + waitAndKill(callback); + } catch(e) { + callback(); + } + }, 500); + } + waitAndKill(cb); }).parallel().done(function() { process.kill(process.pid, 'SIGKILL'); });