From 0eb71d42130b4ec72b1c81ec575488c3377c05eb 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 7d3d267123da95..2cd13a2891068c 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(); @@ -265,6 +247,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) {