From fc1157469830b666e7829327c5e6211c605afdf6 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 26 Jan 2021 14:08:29 +0000 Subject: [PATCH 1/2] add uncaughtException handler --- services/clsi/app.js | 9 +++++++++ services/clsi/config/settings.defaults.js | 2 ++ 2 files changed, 11 insertions(+) diff --git a/services/clsi/app.js b/services/clsi/app.js index 930ebc3e1c..280b869472 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -339,6 +339,15 @@ const loadHttpPort = Settings.internal.load_balancer_agent.local_port if (!module.parent) { // Called directly + + // handle uncaught exceptions when running in production + if (Settings.catchErrors) { + process.removeAllListeners('uncaughtException') + process.on('uncaughtException', (error) => + logger.error({ err: error }, 'uncaughtException') + ) + } + app.listen(port, host, (error) => { if (error) { logger.fatal({ error }, `Error starting CLSI on ${host}:${port}`) diff --git a/services/clsi/config/settings.defaults.js b/services/clsi/config/settings.defaults.js index 72c3471ba9..a0ad8433aa 100644 --- a/services/clsi/config/settings.defaults.js +++ b/services/clsi/config/settings.defaults.js @@ -25,6 +25,8 @@ module.exports = { processLifespanLimitMs: parseInt(process.env.PROCESS_LIFE_SPAN_LIMIT_MS) || 60 * 60 * 24 * 1000 * 2, + catchErrors: process.env.CATCH_ERRORS === 'true', + path: { compilesDir: Path.resolve(__dirname, '../compiles'), outputDir: Path.resolve(__dirname, '../output'), From f0b4f1238b4c608a0754ee9c36ce2df7f6e2bb80 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 26 Jan 2021 16:35:39 +0000 Subject: [PATCH 2/2] provide a /oops-internal endpoint for testing uncaughtExceptions --- services/clsi/app.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/clsi/app.js b/services/clsi/app.js index 280b869472..aee8d44832 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -213,6 +213,12 @@ app.get('/oops', function (req, res, next) { return res.send('error\n') }) +app.get('/oops-internal', function (req, res, next) { + setTimeout(function () { + throw new Error('Test error') + }, 1) +}) + app.get('/status', (req, res, next) => res.send('CLSI is alive\n')) Settings.processTooOld = false