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 1b3fcf7

Browse filesBrowse files
joyeecheungruyadorno
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 514e516 commit 1b3fcf7
Copy full SHA for 1b3fcf7

File tree

Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+16-3Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,20 @@ const noop = () => {};
135135

136136
const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext');
137137

138-
const dc = require('diagnostics_channel');
139-
const netClientSocketChannel = dc.channel('net.client.socket');
140-
const netServerSocketChannel = dc.channel('net.server.socket');
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+
}
141152

142153
const {
143154
hasObserver,
@@ -210,6 +221,7 @@ function connect(...args) {
210221
const options = normalized[0];
211222
debug('createConnection', normalized);
212223
const socket = new Socket(options);
224+
lazyChannels();
213225
if (netClientSocketChannel.hasSubscribers) {
214226
netClientSocketChannel.publish({
215227
socket,
@@ -1756,6 +1768,7 @@ function onconnection(err, clientHandle) {
17561768

17571769
DTRACE_NET_SERVER_CONNECTION(socket);
17581770
self.emit('connection', socket);
1771+
lazyChannels();
17591772
if (netServerSocketChannel.hasSubscribers) {
17601773
netServerSocketChannel.publish({
17611774
socket,
Collapse file

‎test/parallel/test-bootstrap-modules.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ const expectedModules = new Set([
171171
'NativeModule v8',
172172
'NativeModule internal/v8/startup_snapshot',
173173
'NativeModule vm',
174-
'NativeModule diagnostics_channel',
175174
]);
176175

177176
if (!common.isMainThread) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.