-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: improve network family autoselection handle handling
PR-URL: #48464 Fixes: npm/cli#6409 Fixes: KararTY/dank-twitch-irc#13 Fixes: #47644 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
- Loading branch information
1 parent
9117d45
commit fddd3ff
Showing
4 changed files
with
125 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { addresses } = require('../common/internet'); | ||
|
||
const assert = require('assert'); | ||
const { connect } = require('net'); | ||
|
||
// Test that when all errors are returned when no connections succeeded and that the close event is emitted | ||
{ | ||
const connection = connect({ | ||
host: addresses.INET_HOST, | ||
port: 10, | ||
autoSelectFamily: true, | ||
// Purposely set this to a low value because we want all non last connection to fail due to early timeout | ||
autoSelectFamilyAttemptTimeout: 10, | ||
}); | ||
|
||
connection.on('close', common.mustCall()); | ||
connection.on('ready', common.mustNotCall()); | ||
|
||
connection.on('error', common.mustCall((error) => { | ||
assert.ok(connection.autoSelectFamilyAttemptedAddresses.length > 0); | ||
assert.strictEqual(error.constructor.name, 'AggregateError'); | ||
assert.ok(error.errors.length > 0); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { addresses: { INET_HOST } } = require('../common/internet'); | ||
|
||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
} | ||
|
||
const { Socket } = require('net'); | ||
const { TLSSocket } = require('tls'); | ||
|
||
// Test that TLS connecting works with autoSelectFamily when using a backing socket | ||
{ | ||
const socket = new Socket(); | ||
const secureSocket = new TLSSocket(socket); | ||
|
||
secureSocket.on('connect', common.mustCall(() => secureSocket.end())); | ||
|
||
socket.connect({ host: INET_HOST, port: 443, servername: INET_HOST }); | ||
secureSocket.connect({ host: INET_HOST, port: 443, servername: INET_HOST }); | ||
} |