Skip to content

Commit e4e363e

Browse files
indutnyjuanarbol
authored andcommitted
net: fix address iteration with autoSelectFamily
When `autoSelectFamily` is set to `true`, `net.connect` is supposed to try connecting to both IPv4 and IPv6, interleaving the address types. Instead, it appears that the array that holds the addresses in the order they should be attempted was never used after being populated. PR-URL: nodejs#48258 Backport-PR-URL: nodejs#48275 Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent 8ad816d commit e4e363e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/net.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ function lookupAndConnectMultiple(self, async_id_symbol, lookup, host, options,
14181418

14191419
const context = {
14201420
socket: self,
1421-
addresses,
1421+
addresses: toAttempt,
14221422
current: 0,
14231423
port,
14241424
localPort,

test/parallel/test-net-autoselectfamily.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function createDnsServer(ipv6Addrs, ipv4Addrs, cb) {
117117
// Test that only the last successful connection is established.
118118
{
119119
createDnsServer(
120-
'::1',
120+
['2606:4700::6810:85e5', '2606:4700::6810:84e5', '::1'],
121121
['104.20.22.46', '104.20.23.46', '127.0.0.1'],
122122
common.mustCall(function({ dnsServer, lookup }) {
123123
const ipv4Server = createServer((socket) => {
@@ -144,7 +144,14 @@ function createDnsServer(ipv6Addrs, ipv4Addrs, cb) {
144144
connection.on('ready', common.mustCall(() => {
145145
assert.deepStrictEqual(
146146
connection.autoSelectFamilyAttemptedAddresses,
147-
[`::1:${port}`, `104.20.22.46:${port}`, `104.20.23.46:${port}`, `127.0.0.1:${port}`]
147+
[
148+
`2606:4700::6810:85e5:${port}`,
149+
`104.20.22.46:${port}`,
150+
`2606:4700::6810:84e5:${port}`,
151+
`104.20.23.46:${port}`,
152+
`::1:${port}`,
153+
`127.0.0.1:${port}`,
154+
]
148155
);
149156
}));
150157

0 commit comments

Comments
 (0)