Skip to content

Commit 71fe736

Browse files
committed
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.
1 parent 8aa02e8 commit 71fe736

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
@@ -1476,7 +1476,7 @@ function lookupAndConnectMultiple(
14761476

14771477
const context = {
14781478
socket: self,
1479-
addresses,
1479+
addresses: toAttempt,
14801480
current: 0,
14811481
port,
14821482
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)