diff --git a/src/node.cc b/src/node.cc index 472ab81147eb81..e55dda68258d4b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2029,6 +2029,9 @@ static void WaitForInspectorDisconnect(Environment* env) { static void Exit(const FunctionCallbackInfo& args) { WaitForInspectorDisconnect(Environment::GetCurrent(args)); + if (trace_enabled) { + v8_platform.StopTracingAgent(); + } exit(args[0]->Int32Value()); } diff --git a/test/parallel/test-trace-events-process-exit.js b/test/parallel/test-trace-events-process-exit.js new file mode 100644 index 00000000000000..be45cb1d3e0f22 --- /dev/null +++ b/test/parallel/test-trace-events-process-exit.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const fs = require('fs'); + +const FILE_NAME = 'node_trace.1.log'; + +common.refreshTmpDir(); +process.chdir(common.tmpDir); + +const proc = cp.spawn(process.execPath, + [ '--trace-events-enabled', + '-e', 'process.exit()' ]); + +proc.once('exit', common.mustCall(() => { + assert(common.fileExists(FILE_NAME)); + fs.readFile(FILE_NAME, common.mustCall((err, data) => { + const traces = JSON.parse(data.toString()).traceEvents; + assert(traces.length > 0); + })); +}));