Skip to content

Commit 2d6a8c6

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 0336bc7 commit 2d6a8c6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/net.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ function lookupAndConnectMultiple(self, async_id_symbol, lookup, host, options,
14171417

14181418
const context = {
14191419
socket: self,
1420-
addresses,
1420+
addresses: toAttempt,
14211421
current: 0,
14221422
port,
14231423
localPort,

test/parallel/test-net-autoselectfamily.js

+9-2
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)