From 90a5e9389633055e9359b8099ddd0132eb86933b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Jan 2020 13:12:15 +0100 Subject: [PATCH 1/8] dns: default to verbatim=true in dns.lookup() Switch the default from false (reorder the result so that IPv4 addresses come before IPv6 addresses) to true (return them exactly as the resolver sent them to us.) Fixes: https://github.com/nodejs/node/issues/31566 Refs: https://github.com/nodejs/node/issues/6307 Refs: https://github.com/nodejs/node/pull/20710 Reissue of https://github.com/nodejs/node/pull/31567 Reissue of https://github.com/nodejs/node/pull/37681 --- doc/api/dns.md | 7 ++++--- lib/dns.js | 4 ++-- lib/internal/dns/promises.js | 4 ++-- test/sequential/test-net-better-error-messages-port.js | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/api/dns.md b/doc/api/dns.md index cdb948309f173f..868a5039bf237e 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -163,6 +163,9 @@ section if a custom port is used. force legacy IPv4 with `common.localhostIPv4`. test/sequential/test-inspector-open.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while inspector is listening on legacy IPv4 `localhost` by default. test/sequential/test-net-connect-local-error.js: add `family: 4` to `optionsIPv4` and `family: 6` to `optionsIPv6`, because it seems connecting on IPv4 will default to `localhost` which then resolves to `::1` if IPv6 is available and will cause an error. --- test/common/inspector-helper.js | 3 ++- test/parallel/test-cluster-message.js | 2 +- test/parallel/test-http-localaddress.js | 1 + test/parallel/test-http-upgrade-client.js | 1 + test/parallel/test-http2-connect-options.js | 2 +- test/parallel/test-https-localaddress.js | 1 + test/parallel/test-net-dns-lookup.js | 4 ++-- test/parallel/test-net-remote-address-port.js | 2 +- test/parallel/test-tcp-wrap-listen.js | 4 +++- ...-timers-socket-timeout-removes-other-socket-unref-timer.js | 4 ++-- test/parallel/test-tls-client-getephemeralkeyinfo.js | 1 + test/parallel/test-tls-client-mindhsize.js | 1 + test/parallel/test-tls-wrap-econnreset-localaddress.js | 1 + test/sequential/test-https-connect-localport.js | 2 +- test/sequential/test-inspector-open.js | 2 +- test/sequential/test-net-connect-local-error.js | 2 ++ 16 files changed, 22 insertions(+), 11 deletions(-) diff --git a/test/common/inspector-helper.js b/test/common/inspector-helper.js index 666624490e79a9..6a54446ef37039 100644 --- a/test/common/inspector-helper.js +++ b/test/common/inspector-helper.js @@ -393,7 +393,7 @@ class NodeInstance extends EventEmitter { console.log('[test]', `Testing ${path}`); const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null; return this.portPromise.then((port) => new Promise((resolve, reject) => { - const req = http.get({ host, port, path, headers }, (res) => { + const req = http.get({ host, port, family: 4, path, headers }, (res) => { let response = ''; res.setEncoding('utf8'); res @@ -419,6 +419,7 @@ class NodeInstance extends EventEmitter { const port = await this.portPromise; return http.get({ port, + family: 4, path: parseURL(devtoolsUrl).path, headers: { 'Connection': 'Upgrade', diff --git a/test/parallel/test-cluster-message.js b/test/parallel/test-cluster-message.js index 45854c77a5a347..e49bee6bf0a409 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -111,7 +111,7 @@ if (cluster.isWorker) { // When a TCP server is listening in the worker connect to it worker.on('listening', function(address) { - client = net.connect(address.port, function() { + client = net.connect({ port: address.port, family: 4 }, function() { // Send message to worker. worker.send('message from primary'); }); diff --git a/test/parallel/test-http-localaddress.js b/test/parallel/test-http-localaddress.js index e237c3bff1ac84..a0e4bb80a3f8c2 100644 --- a/test/parallel/test-http-localaddress.js +++ b/test/parallel/test-http-localaddress.js @@ -42,6 +42,7 @@ const server = http.createServer((req, res) => { server.listen(0, '127.0.0.1', () => { const options = { host: 'localhost', port: server.address().port, + family: 4, path: '/', method: 'GET', localAddress: '127.0.0.2' }; diff --git a/test/parallel/test-http-upgrade-client.js b/test/parallel/test-http-upgrade-client.js index 8fe756f469f09a..7b5dde540746a6 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -68,6 +68,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() { headers.forEach(function(h) { const req = http.get({ port: port, + family: 4, headers: h }); let sawUpgrade = false; diff --git a/test/parallel/test-http2-connect-options.js b/test/parallel/test-http2-connect-options.js index 0c7ec807b84d38..233ced016974e2 100644 --- a/test/parallel/test-http2-connect-options.js +++ b/test/parallel/test-http2-connect-options.js @@ -22,7 +22,7 @@ const server = http2.createServer((req, res) => { }); server.listen(0, '127.0.0.1', common.mustCall(() => { - const options = { localAddress: '127.0.0.2' }; + const options = { localAddress: '127.0.0.2', family: 4 }; const client = http2.connect( 'http://localhost:' + server.address().port, diff --git a/test/parallel/test-https-localaddress.js b/test/parallel/test-https-localaddress.js index 0ac8414b2d4b35..0de0974dc69b04 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -52,6 +52,7 @@ server.listen(0, '127.0.0.1', function() { const options = { host: 'localhost', port: this.address().port, + family: 4, path: '/', method: 'GET', localAddress: '127.0.0.2', diff --git a/test/parallel/test-net-dns-lookup.js b/test/parallel/test-net-dns-lookup.js index 53052de716ee9e..1ac6525c00d85b 100644 --- a/test/parallel/test-net-dns-lookup.js +++ b/test/parallel/test-net-dns-lookup.js @@ -29,8 +29,8 @@ const server = net.createServer(function(client) { server.close(); }); -server.listen(0, '127.0.0.1', common.mustCall(function() { - net.connect(this.address().port, 'localhost') +server.listen(0, common.localhostIPv4, common.mustCall(function() { + net.connect({ port: this.address().port, host: 'localhost', family: 4 }) .on('lookup', common.mustCall(function(err, ip, type, host) { assert.strictEqual(err, null); assert.strictEqual(ip, '127.0.0.1'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 094206f85df34d..cc14d0c951167d 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -28,7 +28,7 @@ const net = require('net'); let conns_closed = 0; const remoteAddrCandidates = [ common.localhostIPv4 ]; -if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1'); +if (common.hasIPv6) remoteAddrCandidates.push('::1', '::ffff:127.0.0.1'); const remoteFamilyCandidates = ['IPv4']; if (common.hasIPv6) remoteFamilyCandidates.push('IPv6'); diff --git a/test/parallel/test-tcp-wrap-listen.js b/test/parallel/test-tcp-wrap-listen.js index 72981b683ccea3..0cac545e81d785 100644 --- a/test/parallel/test-tcp-wrap-listen.js +++ b/test/parallel/test-tcp-wrap-listen.js @@ -14,7 +14,9 @@ const { const server = new TCP(TCPConstants.SOCKET); -const r = server.bind('0.0.0.0', 0); +const r = (common.hasIPv6 ? + server.bind6('::', 0) : + server.bind('0.0.0.0', 0)); assert.strictEqual(r, 0); let port = {}; server.getsockname(port); diff --git a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js index ccecfe4c63a6a1..5fcd4fa4fee4bc 100644 --- a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js +++ b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js @@ -32,12 +32,12 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => { const countdown = new Countdown(2, () => server.close()); { - const client = net.connect({ port: server.address().port }); + const client = net.connect({ port: server.address().port, family: 4 }); client.on('end', () => countdown.dec()); } { - const client = net.connect({ port: server.address().port }); + const client = net.connect({ port: server.address().port, family: 4 }); client.on('end', () => countdown.dec()); } })); diff --git a/test/parallel/test-tls-client-getephemeralkeyinfo.js b/test/parallel/test-tls-client-getephemeralkeyinfo.js index 73ac215102ddbb..36502da30af8dd 100644 --- a/test/parallel/test-tls-client-getephemeralkeyinfo.js +++ b/test/parallel/test-tls-client-getephemeralkeyinfo.js @@ -40,6 +40,7 @@ function test(size, type, name, cipher) { server.listen(0, '127.0.0.1', common.mustCall(() => { const client = tls.connect({ port: server.address().port, + family: 4, rejectUnauthorized: false }, common.mustCall(function() { const ekeyinfo = client.getEphemeralKeyInfo(); diff --git a/test/parallel/test-tls-client-mindhsize.js b/test/parallel/test-tls-client-mindhsize.js index a6fbc67bd88361..375501829508d7 100644 --- a/test/parallel/test-tls-client-mindhsize.js +++ b/test/parallel/test-tls-client-mindhsize.js @@ -41,6 +41,7 @@ function test(size, err, next) { const client = tls.connect({ minDHSize: 2048, port: this.address().port, + family: 4, rejectUnauthorized: false }, function() { nsuccess++; diff --git a/test/parallel/test-tls-wrap-econnreset-localaddress.js b/test/parallel/test-tls-wrap-econnreset-localaddress.js index 30d3a8873fa8f0..b51ddb29ba8b55 100644 --- a/test/parallel/test-tls-wrap-econnreset-localaddress.js +++ b/test/parallel/test-tls-wrap-econnreset-localaddress.js @@ -16,6 +16,7 @@ const server = net.createServer((c) => { let errored = false; tls.connect({ port: port, + family: 4, localAddress: common.localhostIPv4 }, common.localhostIPv4) .once('error', common.mustCall((e) => { diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index e703fb2287d369..ac82d5210066a4 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -23,7 +23,7 @@ const assert = require('assert'); host: 'localhost', pathname: '/', port, - family: 4, + // family: 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => { diff --git a/test/sequential/test-inspector-open.js b/test/sequential/test-inspector-open.js index 190a99e7282e52..847f0ab6926f67 100644 --- a/test/sequential/test-inspector-open.js +++ b/test/sequential/test-inspector-open.js @@ -80,7 +80,7 @@ function reopenAfterClose(msg) { } function ping(port, callback) { - net.connect(port) + net.connect({ port, family: 4 }) .on('connect', function() { close(this); }) .on('error', function(err) { close(this, err); }); diff --git a/test/sequential/test-net-connect-local-error.js b/test/sequential/test-net-connect-local-error.js index 030c4de750cb4d..7fa33b07597547 100644 --- a/test/sequential/test-net-connect-local-error.js +++ b/test/sequential/test-net-connect-local-error.js @@ -9,6 +9,7 @@ const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE']; const optionsIPv4 = { port: common.PORT, + family: 4, localPort: common.PORT + 1, localAddress: common.localhostIPv4 }; @@ -16,6 +17,7 @@ const optionsIPv4 = { const optionsIPv6 = { host: '::1', port: common.PORT + 2, + family: 6, localPort: common.PORT + 3, localAddress: '::1', }; From 88d5f2421e214e60433e2bf21e7e195501d3a17a Mon Sep 17 00:00:00 2001 From: treysis Date: Sat, 27 Mar 2021 19:46:13 +0100 Subject: [PATCH 3/8] Adjust doc/api/dns.md --- doc/api/dns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/dns.md b/doc/api/dns.md index 868a5039bf237e..312c746067087f 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -164,7 +164,7 @@ section if a custom port is used. added: v0.1.90 changes: - version: REPLACEME - pr-url: https://github.com/nodejs/node/pull/37681 + pr-url: https://github.com/nodejs/node/pull/37931 description: The `verbatim` options defaults to `true` now. - version: v8.5.0 pr-url: https://github.com/nodejs/node/pull/14731 From a45f06651c651d972efee73c355b7fef04706e0b Mon Sep 17 00:00:00 2001 From: treysis Date: Sat, 27 Mar 2021 22:55:33 +0100 Subject: [PATCH 4/8] SmartOS fixes for the test suite Explanations: test/parallel/test-net-connect-options-port.js: add `family: 4` at various places to force `localhost` or default `localhost` to be resolved to legacy IPv4 addresses. test/parallel/test-net-pingpong.js: change `localhost` to `127.0.0.1` because test is aimed at legacy IPv4, so it can be forced to literal IPv4 address without problem. NEEDS TESTING: does `pingPongTest(0);` pass? test/parallel/test-net-remote-address-port.js: change `localhost` to `127.0.0.1` and force IPv4 by adding `family: 4` because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/parallel/test-net-writable.js: listen on `common.localhostIPv4` and add `family: 4` to connect to force IPv4. because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/sequential/test-https-connect-localport.js: revert previous change, i.e. readd `family: 4` to `https.get`. Change `localhost` on listen to `common.localhostIPv4` to force legacy IPv4. --- .../parallel/test-net-connect-options-port.js | 36 ++++++++++++------- test/parallel/test-net-pingpong.js | 2 +- test/parallel/test-net-remote-address-port.js | 9 +++-- test/parallel/test-net-writable.js | 6 ++-- .../test-https-connect-localport.js | 4 +-- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index 74e78240abb5ba..d018f29ededb0b 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -83,7 +83,7 @@ const net = require('net'); } }, expectedConnections)); - server.listen(0, 'localhost', common.mustCall(() => { + server.listen(0, common.localhostIPv4, common.mustCall(() => { const port = server.address().port; // Total connections = 3 * 4(canConnect) * 6(doConnect) = 72 @@ -133,28 +133,35 @@ function doConnect(args, getCb) { } function syncFailToConnect(port, assertErr, optOnly) { + const family = 4; if (!optOnly) { // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], () => common.mustNotCall()); + const portArgFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port})`); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], + const portHostArgFunctions = doConnect([{ port, + host: 'localhost', + family }], () => common.mustNotCall()); for (const fn of portHostArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); } } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], () => common.mustNotCall()); + const portOptFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portOptFunctions) { assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }], + const portHostOptFunctions = doConnect([{ port: port, + host: 'localhost', + family }], () => common.mustNotCall()); for (const fn of portHostOptFunctions) { assert.throws(fn, @@ -165,27 +172,30 @@ function syncFailToConnect(port, assertErr, optOnly) { function canConnect(port) { const noop = () => common.mustCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], noop); + const portArgFunctions = doConnect([{ port, family }], noop); for (const fn of portArgFunctions) { fn(); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], noop); + const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostArgFunctions) { fn(); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], noop); + const portOptFunctions = doConnect([{ port, family }], noop); for (const fn of portOptFunctions) { fn(); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostOptFns) { fn(); } @@ -198,20 +208,22 @@ function asyncFailToConnect(port) { }); const dont = () => common.mustNotCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], dont); + const portArgFunctions = doConnect([{ port, family }], dont); for (const fn of portArgFunctions) { fn().on('error', onError()); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], dont); + const portOptFunctions = doConnect([{ port, family }], dont); for (const fn of portOptFunctions) { fn().on('error', onError()); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + dont); for (const fn of portHostOptFns) { fn().on('error', onError()); } diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index 7fb6678fe1a897..b1fd2290d0f100 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -130,6 +130,6 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); pingPongTest(common.PIPE); pingPongTest(0); -pingPongTest(0, 'localhost'); +pingPongTest(0, '127.0.0.1'); if (common.hasIPv6) pingPongTest(0, '::1'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index cc14d0c951167d..324c82b654aa44 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -48,9 +48,12 @@ const server = net.createServer(common.mustCall(function(socket) { socket.resume(); }, 2)); -server.listen(0, 'localhost', function() { - const client = net.createConnection(this.address().port, 'localhost'); - const client2 = net.createConnection(this.address().port); +server.listen(0, '127.0.0.1', function() { + const client = net.createConnection({ port: this.address().port, + host: 'localhost', + family: 4 }); + const client2 = net.createConnection({ port: this.address().port, + family: 4 }); client.on('connect', function() { assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); diff --git a/test/parallel/test-net-writable.js b/test/parallel/test-net-writable.js index dcbb64e272b830..5ed5e6b8e915c7 100644 --- a/test/parallel/test-net-writable.js +++ b/test/parallel/test-net-writable.js @@ -6,8 +6,10 @@ const net = require('net'); const server = net.createServer(common.mustCall(function(s) { server.close(); s.end(); -})).listen(0, 'localhost', common.mustCall(function() { - const socket = net.connect(this.address().port, 'localhost'); +})).listen(0, common.localhostIPv4, common.mustCall(function() { + const socket = net.connect({ port: this.address().port, + host: 'localhost', + family: 4 }); socket.on('end', common.mustCall(() => { assert.strictEqual(socket.writable, true); socket.write('hello world'); diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index ac82d5210066a4..6e3e451ee8136e 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -17,13 +17,13 @@ const assert = require('assert'); res.end(); })); - server.listen(0, 'localhost', common.mustCall(() => { + server.listen(0, common.localhostIPv4, common.mustCall(() => { const port = server.address().port; const req = https.get({ host: 'localhost', pathname: '/', port, - // family: 4, + family: 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => { From ea90294c40332e2c2b261474c91deecc5fbcadab Mon Sep 17 00:00:00 2001 From: treysis Date: Sun, 28 Mar 2021 21:54:52 +0200 Subject: [PATCH 5/8] Revert "SmartOS fixes for the test suite" This reverts commit a45f06651c651d972efee73c355b7fef04706e0b. --- .../parallel/test-net-connect-options-port.js | 36 +++++++------------ test/parallel/test-net-pingpong.js | 2 +- test/parallel/test-net-remote-address-port.js | 9 ++--- test/parallel/test-net-writable.js | 6 ++-- .../test-https-connect-localport.js | 4 +-- 5 files changed, 20 insertions(+), 37 deletions(-) diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index d018f29ededb0b..74e78240abb5ba 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -83,7 +83,7 @@ const net = require('net'); } }, expectedConnections)); - server.listen(0, common.localhostIPv4, common.mustCall(() => { + server.listen(0, 'localhost', common.mustCall(() => { const port = server.address().port; // Total connections = 3 * 4(canConnect) * 6(doConnect) = 72 @@ -133,35 +133,28 @@ function doConnect(args, getCb) { } function syncFailToConnect(port, assertErr, optOnly) { - const family = 4; if (!optOnly) { // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], - () => common.mustNotCall()); + const portArgFunctions = doConnect([port], () => common.mustNotCall()); for (const fn of portArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port})`); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([{ port, - host: 'localhost', - family }], + const portHostArgFunctions = doConnect([port, 'localhost'], () => common.mustNotCall()); for (const fn of portHostArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); } } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], - () => common.mustNotCall()); + const portOptFunctions = doConnect([{ port }], () => common.mustNotCall()); for (const fn of portOptFunctions) { assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFunctions = doConnect([{ port: port, - host: 'localhost', - family }], + const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }], () => common.mustNotCall()); for (const fn of portHostOptFunctions) { assert.throws(fn, @@ -172,30 +165,27 @@ function syncFailToConnect(port, assertErr, optOnly) { function canConnect(port) { const noop = () => common.mustCall(); - const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], noop); + const portArgFunctions = doConnect([port], noop); for (const fn of portArgFunctions) { fn(); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }], - noop); + const portHostArgFunctions = doConnect([port, 'localhost'], noop); for (const fn of portHostArgFunctions) { fn(); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], noop); + const portOptFunctions = doConnect([{ port }], noop); for (const fn of portOptFunctions) { fn(); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost', family }], - noop); + const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop); for (const fn of portHostOptFns) { fn(); } @@ -208,22 +198,20 @@ function asyncFailToConnect(port) { }); const dont = () => common.mustNotCall(); - const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], dont); + const portArgFunctions = doConnect([port], dont); for (const fn of portArgFunctions) { fn().on('error', onError()); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], dont); + const portOptFunctions = doConnect([{ port }], dont); for (const fn of portOptFunctions) { fn().on('error', onError()); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost', family }], - dont); + const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont); for (const fn of portHostOptFns) { fn().on('error', onError()); } diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index b1fd2290d0f100..7fb6678fe1a897 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -130,6 +130,6 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); pingPongTest(common.PIPE); pingPongTest(0); -pingPongTest(0, '127.0.0.1'); +pingPongTest(0, 'localhost'); if (common.hasIPv6) pingPongTest(0, '::1'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 324c82b654aa44..cc14d0c951167d 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -48,12 +48,9 @@ const server = net.createServer(common.mustCall(function(socket) { socket.resume(); }, 2)); -server.listen(0, '127.0.0.1', function() { - const client = net.createConnection({ port: this.address().port, - host: 'localhost', - family: 4 }); - const client2 = net.createConnection({ port: this.address().port, - family: 4 }); +server.listen(0, 'localhost', function() { + const client = net.createConnection(this.address().port, 'localhost'); + const client2 = net.createConnection(this.address().port); client.on('connect', function() { assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); diff --git a/test/parallel/test-net-writable.js b/test/parallel/test-net-writable.js index 5ed5e6b8e915c7..dcbb64e272b830 100644 --- a/test/parallel/test-net-writable.js +++ b/test/parallel/test-net-writable.js @@ -6,10 +6,8 @@ const net = require('net'); const server = net.createServer(common.mustCall(function(s) { server.close(); s.end(); -})).listen(0, common.localhostIPv4, common.mustCall(function() { - const socket = net.connect({ port: this.address().port, - host: 'localhost', - family: 4 }); +})).listen(0, 'localhost', common.mustCall(function() { + const socket = net.connect(this.address().port, 'localhost'); socket.on('end', common.mustCall(() => { assert.strictEqual(socket.writable, true); socket.write('hello world'); diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index 6e3e451ee8136e..ac82d5210066a4 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -17,13 +17,13 @@ const assert = require('assert'); res.end(); })); - server.listen(0, common.localhostIPv4, common.mustCall(() => { + server.listen(0, 'localhost', common.mustCall(() => { const port = server.address().port; const req = https.get({ host: 'localhost', pathname: '/', port, - family: 4, + // family: 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => { From 618579b6e0691397233a7409dd996456035213c1 Mon Sep 17 00:00:00 2001 From: treysis Date: Sun, 28 Mar 2021 21:55:42 +0200 Subject: [PATCH 6/8] Remove dns.ADDRCONFIG from net.js --- lib/net.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/net.js b/lib/net.js index 94aae1fa9f736d..c55954ba5175e9 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1023,13 +1023,6 @@ function lookupAndConnect(self, options) { hints: options.hints || 0 }; - if (!isWindows && - dnsopts.family !== 4 && - dnsopts.family !== 6 && - dnsopts.hints === 0) { - dnsopts.hints = dns.ADDRCONFIG; - } - debug('connect: find host', host); debug('connect: dns options', dnsopts); self._host = host; From 6667100c82676a3e1ab9916cd481959ee6a6f187 Mon Sep 17 00:00:00 2001 From: treysis Date: Sun, 28 Mar 2021 22:45:16 +0200 Subject: [PATCH 7/8] Fix test/sequential/test-tls-securepair-client.js --- test/sequential/test-tls-securepair-client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-tls-securepair-client.js b/test/sequential/test-tls-securepair-client.js index d5e2b7b7d2b08d..ca656f107ce0b9 100644 --- a/test/sequential/test-tls-securepair-client.js +++ b/test/sequential/test-tls-securepair-client.js @@ -132,7 +132,7 @@ function test(keyPath, certPath, check, next) { pair.encrypted.pipe(s); s.pipe(pair.encrypted); - s.connect(port); + s.connect({ port, family: 4 }); s.on('connect', function() { console.log('client connected'); From 5cc6082371aab9502213065b871f3ad3d4e20c98 Mon Sep 17 00:00:00 2001 From: treysis Date: Mon, 29 Mar 2021 12:09:09 +0200 Subject: [PATCH 8/8] Update test/sequential/test-https-connect-localport.js Co-authored-by: Antoine du Hamel --- test/sequential/test-https-connect-localport.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index ac82d5210066a4..d52c55a6d74fa0 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -23,7 +23,6 @@ const assert = require('assert'); host: 'localhost', pathname: '/', port, - // family: 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => {