From b5fe27ccc97a5e36ffa5e8535b13dda8de6515ce Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 10 Feb 2019 19:00:54 +0800 Subject: [PATCH] process: delay setup of global exception handlers Since bootstrap/node.js performs the setup synchronously, the process exception handlers do not have to setup so early in the bootstrap process - any fatal errors thrown before user code execution should simply crash the process, and we do not care about any clean up at that point. We don't care about emitting any events if the process crash upon bootstrap either. PR-URL: https://github.com/nodejs/node/pull/26061 Reviewed-By: Anna Henningsen Reviewed-By: Minwoo Jung Reviewed-By: Gus Caplan --- lib/internal/bootstrap/node.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index ca9d6c60cf3868..e3f85ec0afe38c 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -46,24 +46,6 @@ setupTraceCategoryState(); setupProcessObject(); -// TODO(joyeecheung): this does not have to done so early, any fatal errors -// thrown before user code execution should simply crash the process -// and we do not care about any clean up at that point. We don't care -// about emitting any events if the process crash upon bootstrap either. -{ - const { - fatalException, - setUncaughtExceptionCaptureCallback, - hasUncaughtExceptionCaptureCallback - } = NativeModule.require('internal/process/execution'); - - process._fatalException = fatalException; - process.setUncaughtExceptionCaptureCallback = - setUncaughtExceptionCaptureCallback; - process.hasUncaughtExceptionCaptureCallback = - hasUncaughtExceptionCaptureCallback; -} - setupGlobalProxy(); setupBuffer(); @@ -303,6 +285,20 @@ Object.defineProperty(process, 'features', { } }); +{ + const { + fatalException, + setUncaughtExceptionCaptureCallback, + hasUncaughtExceptionCaptureCallback + } = NativeModule.require('internal/process/execution'); + + process._fatalException = fatalException; + process.setUncaughtExceptionCaptureCallback = + setUncaughtExceptionCaptureCallback; + process.hasUncaughtExceptionCaptureCallback = + hasUncaughtExceptionCaptureCallback; +} + // User-facing NODE_V8_COVERAGE environment variable that writes // ScriptCoverage to a specified file. if (process.env.NODE_V8_COVERAGE) {