Skip to content

Commit d3637cd

Browse files
indutnyruyadorno
authored andcommittedAug 14, 2023
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: #48258 Backport-PR-URL: #49016 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent e8289a8 commit d3637cd

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
@@ -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

+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)
Please sign in to comment.