Skip to content

Commit 2ce8b97

Browse files
theanarkhrichardlau
authored andcommitted
src: fix unix abstract socket path for trace event
PR-URL: #50858 Reviewed-By: James M Snell <[email protected]>
1 parent 562947e commit 2ce8b97

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/pipe_wrap.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,15 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
230230
if (err) {
231231
delete req_wrap;
232232
} else {
233-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(net, native),
233+
const char* path_type = (*name)[0] == '\0' ? "abstract socket" : "file";
234+
const char* pipe_path = (*name)[0] == '\0' ? (*name) + 1 : *name;
235+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(net, native),
234236
"connect",
235237
req_wrap,
238+
"path_type",
239+
path_type,
236240
"pipe_path",
237-
TRACE_STR_COPY(*name));
241+
TRACE_STR_COPY(pipe_path));
238242
}
239243

240244
args.GetReturnValue().Set(err);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
const fs = require('fs');
6+
const tmpdir = require('../common/tmpdir');
7+
8+
if (!common.isLinux) common.skip();
9+
10+
const CODE = `
11+
const net = require('net');
12+
net.connect('${common.PIPE}').on('error', () => {});
13+
net.connect('\\0${common.PIPE}').on('error', () => {});
14+
`;
15+
16+
tmpdir.refresh();
17+
const FILE_NAME = tmpdir.resolve('node_trace.1.log');
18+
19+
const proc = cp.spawn(process.execPath,
20+
[ '--trace-events-enabled',
21+
'--trace-event-categories', 'node.net.native',
22+
'-e', CODE ],
23+
{ cwd: tmpdir.path });
24+
25+
proc.once('exit', common.mustCall(() => {
26+
assert(fs.existsSync(FILE_NAME));
27+
fs.readFile(FILE_NAME, common.mustCall((err, data) => {
28+
const traces = JSON.parse(data.toString()).traceEvents;
29+
assert(traces.length > 0);
30+
let count = 0;
31+
traces.forEach((trace) => {
32+
if (trace.cat === 'node,node.net,node.net.native' &&
33+
trace.name === 'connect') {
34+
count++;
35+
if (trace.ph === 'b') {
36+
assert.ok(!!trace.args.path_type);
37+
assert.ok(!!trace.args.pipe_path);
38+
}
39+
}
40+
});
41+
assert.strictEqual(count, 4);
42+
}));
43+
}));

0 commit comments

Comments
 (0)