Skip to content

Commit 5cb5c65

Browse files
joyeecheungdanielleadams
authored andcommitted
net: create diagnostics channels lazily
PR-URL: #38905 Refs: #35711 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent befe01c commit 5cb5c65

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: lib/net.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ const isWindows = process.platform === 'win32';
134134
const noop = () => {};
135135

136136
const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext');
137+
138+
let netClientSocketChannel;
139+
let netServerSocketChannel;
140+
function lazyChannels() {
141+
// TODO(joyeecheung): support diagnostics channels in the snapshot.
142+
// For now it is fine to create them lazily when there isn't a snapshot to
143+
// build. If users need the channels they would have to create them first
144+
// before invoking any built-ins that would publish to these channels
145+
// anyway.
146+
if (netClientSocketChannel === undefined) {
147+
const dc = require('diagnostics_channel');
148+
netClientSocketChannel = dc.channel('net.client.socket');
149+
netServerSocketChannel = dc.channel('net.server.socket');
150+
}
151+
}
152+
137153
const {
138154
hasObserver,
139155
startPerf,
@@ -205,7 +221,7 @@ function connect(...args) {
205221
const options = normalized[0];
206222
debug('createConnection', normalized);
207223
const socket = new Socket(options);
208-
224+
lazyChannels();
209225
if (options.timeout) {
210226
socket.setTimeout(options.timeout);
211227
}
@@ -1737,6 +1753,7 @@ function onconnection(err, clientHandle) {
17371753

17381754
DTRACE_NET_SERVER_CONNECTION(socket);
17391755
self.emit('connection', socket);
1756+
lazyChannels();
17401757
}
17411758

17421759
/**

0 commit comments

Comments
 (0)