Skip to content

Commit a1d7ed7

Browse files
addaleaxMylesBorins
authored andcommitted
tracing: fix static destruction order issue
Sometimes, the `parallel/test-tracing-no-crash` would not work as expected, at least on Windows, because there is a static destruction race between tearing down the `NodeTraceWriter` instance and the per-process options struct. If the per-process options were destroyed before the `NodeTraceWriter`, the reference to the tracing filename would be gone before opening the file was attempted. This can be solved by creating a copy of the string when creating the `NodeTraceWriter` instance rather than taking a reference. Fixes: #22523 PR-URL: #24123 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent abe3eda commit a1d7ed7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/tracing/node_trace_writer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class NodeTraceWriter : public AsyncTraceWriter {
6161
int highest_request_id_completed_ = 0;
6262
int total_traces_ = 0;
6363
int file_num_ = 0;
64-
const std::string& log_file_pattern_;
64+
std::string log_file_pattern_;
6565
std::ostringstream stream_;
6666
std::unique_ptr<TraceWriter> json_trace_writer_;
6767
bool exited_ = false;

test/parallel/test-tracing-no-crash.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ function CheckNoSignalAndErrorCodeOne(code, signal) {
88
assert.strictEqual(code, 1);
99
}
1010

11-
const child = spawn(process.execPath,
12-
['--trace-event-categories', 'madeup', '-e',
13-
'throw new Error()'], { stdio: 'inherit' });
11+
const child = spawn(process.execPath, [
12+
'--trace-event-categories', 'madeup', '-e', 'throw new Error()'
13+
], { stdio: [ 'inherit', 'inherit', 'pipe' ] });
1414
child.on('exit', common.mustCall(CheckNoSignalAndErrorCodeOne));
15+
16+
let stderr;
17+
child.stderr.setEncoding('utf8');
18+
child.stderr.on('data', (chunk) => stderr += chunk);
19+
child.stderr.on('end', common.mustCall(() => {
20+
assert(stderr.includes('throw new Error()'), stderr);
21+
assert(!stderr.includes('Could not open trace file'), stderr);
22+
}));

0 commit comments

Comments
 (0)