Skip to content

Commit a86b71f

Browse files
joyeecheungtargos
authored andcommitted
src: disconnect inspector before exiting out of fatal exception
So that coverage, .etc are properly written in case of a normal fatal exception. PR-URL: #29611 Fixes: #29570 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com>
1 parent 8d88010 commit a86b71f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/node_errors.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ void TriggerUncaughtException(Isolate* isolate,
980980

981981
// Now we are certain that the exception is fatal.
982982
ReportFatalException(env, error, message, EnhanceFatalException::kEnhance);
983+
#if HAVE_INSPECTOR
984+
profiler::EndStartedProfilers(env);
985+
#endif
983986

984987
// If the global uncaught exception handler sets process.exitCode,
985988
// exit with that code. Otherwise, exit with 1.

test/fixtures/v8-coverage/throw.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const a = 99;
2+
if (true) {
3+
const b = 101;
4+
} else {
5+
const c = 102;
6+
}
7+
throw new Error('test');

test/parallel/test-v8-coverage.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ function nextdir() {
3535
assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0);
3636
}
3737

38+
// Outputs coverage when error is thrown in first tick.
39+
{
40+
const coverageDirectory = path.join(tmpdir.path, nextdir());
41+
const output = spawnSync(process.execPath, [
42+
require.resolve('../fixtures/v8-coverage/throw')
43+
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
44+
if (output.status !== 1) {
45+
console.log(output.stderr.toString());
46+
}
47+
assert.strictEqual(output.status, 1);
48+
const fixtureCoverage = getFixtureCoverage('throw.js', coverageDirectory);
49+
assert.ok(fixtureCoverage, 'coverage not found for file');
50+
// First branch executed.
51+
assert.strictEqual(fixtureCoverage.functions[0].ranges[0].count, 1);
52+
// Second branch did not execute.
53+
assert.strictEqual(fixtureCoverage.functions[0].ranges[1].count, 0);
54+
}
55+
3856
// Outputs coverage when process.exit(1) exits process.
3957
{
4058
const coverageDirectory = path.join(tmpdir.path, nextdir());

0 commit comments

Comments
 (0)