Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,9 @@ static void WaitForInspectorDisconnect(Environment* env) {

static void Exit(const FunctionCallbackInfo<Value>& args) {
WaitForInspectorDisconnect(Environment::GetCurrent(args));
if (trace_enabled) {
v8_platform.StopTracingAgent();
}
exit(args[0]->Int32Value());
}

Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-trace-events-process-exit.js
Original file line number Diff line number Diff line change
@@ -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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fs.readFileSync here, the async version is not guaranteed to complete. In fact, it probably doesn't but that goes unnoticed because the common.mustCall(...) isn't checked as you're already inside an exit handler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a child process 'exit' event, not process.exit(). fs.readFileSync() is probably a simpler idea either way though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how all of the other trace-events tests work. I can change it, but at least it should be consistent.

const traces = JSON.parse(data.toString()).traceEvents;
assert(traces.length > 0);
}));
}));