Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5cb5c65

Browse filesBrowse files
joyeecheungdanielleadams
authored andcommitted
net: create diagnostics channels lazily
PR-URL: #38905 Refs: #35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent befe01c commit 5cb5c65
Copy full SHA for 5cb5c65

File tree

Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+18-1Lines changed: 18 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.