mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
net: always publish to 'net.client.socket' diagnostics channel
Previously, the 'net.client.socket' diagnostics channel was only published to when `net.connect()` was called. This change ensures the message is also published for the following calls: - net.createConnection() - net.Socket#connect() - tls.connect() Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: https://github.com/nodejs/node/pull/58349 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: theanarkh <theratliter@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
This commit is contained in:
parent
fdfd0fd7b5
commit
9eb9c26b26
|
|
@ -1292,9 +1292,9 @@ Emitted when a `import()` throws an error. See [`error` event][].
|
|||
|
||||
`net.client.socket`
|
||||
|
||||
* `socket` {net.Socket}
|
||||
* `socket` {net.Socket|tls.TLSSocket}
|
||||
|
||||
Emitted when a new TCP or pipe client socket is created.
|
||||
Emitted when a new TCP or pipe client socket connection is created.
|
||||
|
||||
`net.server.socket`
|
||||
|
||||
|
|
|
|||
11
lib/net.js
11
lib/net.js
|
|
@ -238,11 +238,6 @@ function connect(...args) {
|
|||
debug('createConnection', normalized);
|
||||
const socket = new Socket(options);
|
||||
|
||||
if (netClientSocketChannel.hasSubscribers) {
|
||||
netClientSocketChannel.publish({
|
||||
socket,
|
||||
});
|
||||
}
|
||||
if (options.timeout) {
|
||||
socket.setTimeout(options.timeout);
|
||||
}
|
||||
|
|
@ -1238,6 +1233,12 @@ Socket.prototype.connect = function(...args) {
|
|||
const options = normalized[0];
|
||||
const cb = normalized[1];
|
||||
|
||||
if (netClientSocketChannel.hasSubscribers) {
|
||||
netClientSocketChannel.publish({
|
||||
socket: this,
|
||||
});
|
||||
}
|
||||
|
||||
if (cb !== null) {
|
||||
this.once('connect', cb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
// This test ensures that the 'net.client.socket' diagnostics channel publishes
|
||||
// a message when tls.connect() is used to create a socket connection.
|
||||
|
||||
const assert = require('assert');
|
||||
const dc = require('diagnostics_channel');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const tls = require('tls');
|
||||
|
||||
const options = {
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem'),
|
||||
rejectUnauthorized: false,
|
||||
};
|
||||
|
||||
dc.subscribe('net.client.socket', common.mustCall(({ socket }) => {
|
||||
assert.strictEqual(socket instanceof tls.TLSSocket, true);
|
||||
}));
|
||||
|
||||
const server = tls.createServer(options, common.mustCall((socket) => {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
}));
|
||||
|
||||
server.listen({ port: 0 }, common.mustCall(() => {
|
||||
const { port } = server.address();
|
||||
tls.connect(port, options);
|
||||
}));
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
const Countdown = require('../common/countdown');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
const dc = require('diagnostics_channel');
|
||||
|
|
@ -18,19 +19,23 @@ function testDiagnosticChannel(subscribers, test, after) {
|
|||
|
||||
const testSuccessfulListen = common.mustCall(() => {
|
||||
let cb;
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.destroy();
|
||||
const netClientSocketCount = 3;
|
||||
const countdown = new Countdown(netClientSocketCount, () => {
|
||||
server.close();
|
||||
cb();
|
||||
}));
|
||||
});
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.destroy();
|
||||
countdown.dec();
|
||||
}, netClientSocketCount));
|
||||
|
||||
dc.subscribe('net.client.socket', common.mustCall(({ socket }) => {
|
||||
assert.strictEqual(isNetSocket(socket), true);
|
||||
}));
|
||||
}, netClientSocketCount));
|
||||
|
||||
dc.subscribe('net.server.socket', common.mustCall(({ socket }) => {
|
||||
assert.strictEqual(isNetSocket(socket), true);
|
||||
}));
|
||||
}, netClientSocketCount));
|
||||
|
||||
testDiagnosticChannel(
|
||||
{
|
||||
|
|
@ -48,8 +53,13 @@ const testSuccessfulListen = common.mustCall(() => {
|
|||
common.mustCall((callback) => {
|
||||
cb = callback;
|
||||
server.listen({ port: 0, customOption: true }, () => {
|
||||
// All supported ways of creating a net client socket connection.
|
||||
const { port } = server.address();
|
||||
net.connect(port);
|
||||
|
||||
net.createConnection(port);
|
||||
|
||||
new net.Socket().connect(port);
|
||||
});
|
||||
}),
|
||||
testFailingListen
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user