mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
net: create diagnostics channels lazily
PR-URL: https://github.com/nodejs/node/pull/38905 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
19
lib/net.js
19
lib/net.js
@@ -131,9 +131,20 @@ const noop = () => {};
|
||||
|
||||
const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext');
|
||||
|
||||
const dc = require('diagnostics_channel');
|
||||
const netClientSocketChannel = dc.channel('net.client.socket');
|
||||
const netServerSocketChannel = dc.channel('net.server.socket');
|
||||
let netClientSocketChannel;
|
||||
let netServerSocketChannel;
|
||||
function lazyChannels() {
|
||||
// TODO(joyeecheung): support diagnostics channels in the snapshot.
|
||||
// For now it is fine to create them lazily when there isn't a snapshot to
|
||||
// build. If users need the channels they would have to create them first
|
||||
// before invoking any built-ins that would publish to these channels
|
||||
// anyway.
|
||||
if (netClientSocketChannel === undefined) {
|
||||
const dc = require('diagnostics_channel');
|
||||
netClientSocketChannel = dc.channel('net.client.socket');
|
||||
netServerSocketChannel = dc.channel('net.server.socket');
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
hasObserver,
|
||||
@@ -206,6 +217,7 @@ function connect(...args) {
|
||||
const options = normalized[0];
|
||||
debug('createConnection', normalized);
|
||||
const socket = new Socket(options);
|
||||
lazyChannels();
|
||||
if (netClientSocketChannel.hasSubscribers) {
|
||||
netClientSocketChannel.publish({
|
||||
socket,
|
||||
@@ -1739,6 +1751,7 @@ function onconnection(err, clientHandle) {
|
||||
socket.server = self;
|
||||
socket._server = self;
|
||||
self.emit('connection', socket);
|
||||
lazyChannels();
|
||||
if (netServerSocketChannel.hasSubscribers) {
|
||||
netServerSocketChannel.publish({
|
||||
socket,
|
||||
|
||||
@@ -170,7 +170,6 @@ const expectedModules = new Set([
|
||||
'NativeModule v8',
|
||||
'NativeModule internal/v8/startup_snapshot',
|
||||
'NativeModule vm',
|
||||
'NativeModule diagnostics_channel',
|
||||
]);
|
||||
|
||||
if (!common.isMainThread) {
|
||||
|
||||
Reference in New Issue
Block a user