From 83fc7ad96a6ef4ad95d86aac94ecf2c0b3d770d3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 19 Sep 2019 11:36:02 +0900 Subject: [PATCH 1/3] src: disconnect inspector before exiting out of fatal exception So that coverage, .etc are properly written in case of a normal fatal exception. --- src/node_errors.cc | 1 + test/fixtures/v8-coverage/throw.js | 7 +++++++ test/parallel/test-v8-coverage.js | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/fixtures/v8-coverage/throw.js diff --git a/src/node_errors.cc b/src/node_errors.cc index 0214521144c607..175cc640a20a18 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -978,6 +978,7 @@ void TriggerUncaughtException(Isolate* isolate, // Now we are certain that the exception is fatal. ReportFatalException(env, error, message, EnhanceFatalException::kEnhance); + WaitForInspectorDisconnect(env); // If the global uncaught exception handler sets process.exitCode, // exit with that code. Otherwise, exit with 1. diff --git a/test/fixtures/v8-coverage/throw.js b/test/fixtures/v8-coverage/throw.js new file mode 100644 index 00000000000000..7436fc99786391 --- /dev/null +++ b/test/fixtures/v8-coverage/throw.js @@ -0,0 +1,7 @@ +const a = 99; +if (true) { + const b = 101; +} else { + const c = 102; +} +throw new Error('test'); diff --git a/test/parallel/test-v8-coverage.js b/test/parallel/test-v8-coverage.js index 02ace7af9cdd78..4dc66d5be6451b 100644 --- a/test/parallel/test-v8-coverage.js +++ b/test/parallel/test-v8-coverage.js @@ -35,6 +35,24 @@ function nextdir() { assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0); } +// Outputs coverage when process.exit(1) exits process. +{ + const coverageDirectory = path.join(tmpdir.path, nextdir()); + const output = spawnSync(process.execPath, [ + require.resolve('../fixtures/v8-coverage/throw') + ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); + if (output.status !== 1) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 1); + const fixtureCoverage = getFixtureCoverage('throw.js', coverageDirectory); + assert.ok(fixtureCoverage, 'coverage not found for file'); + // First branch executed. + assert.strictEqual(fixtureCoverage.functions[0].ranges[0].count, 1); + // Second branch did not execute. + assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0); +} + // Outputs coverage when process.exit(1) exits process. { const coverageDirectory = path.join(tmpdir.path, nextdir()); From 35b3eb914d12863b86fbe2a57485087a5bf23f31 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 19 Sep 2019 14:22:29 +0900 Subject: [PATCH 2/3] fixup! src: disconnect inspector before exiting out of fatal exception --- src/node_errors.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 175cc640a20a18..b33e4936ae7a71 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -978,7 +978,9 @@ void TriggerUncaughtException(Isolate* isolate, // Now we are certain that the exception is fatal. ReportFatalException(env, error, message, EnhanceFatalException::kEnhance); - WaitForInspectorDisconnect(env); +#if HAVE_INSPECTOR + profiler::EndStartedProfilers(env); +#endif // If the global uncaught exception handler sets process.exitCode, // exit with that code. Otherwise, exit with 1. From 07c3ae3b9b571102d507c26391d258115bec2885 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 20 Sep 2019 10:11:09 +0900 Subject: [PATCH 3/3] fixup! fixup! src: disconnect inspector before exiting out of fatal exception --- test/parallel/test-v8-coverage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-v8-coverage.js b/test/parallel/test-v8-coverage.js index 4dc66d5be6451b..2e70ce91fead6d 100644 --- a/test/parallel/test-v8-coverage.js +++ b/test/parallel/test-v8-coverage.js @@ -35,7 +35,7 @@ function nextdir() { assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0); } -// Outputs coverage when process.exit(1) exits process. +// Outputs coverage when error is thrown in first tick. { const coverageDirectory = path.join(tmpdir.path, nextdir()); const output = spawnSync(process.execPath, [