From a05f72f9ca48986841e503e59fd7d3d10d3db343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 20 Jul 2023 15:20:44 +0200 Subject: [PATCH 01/10] test: delete test-net-bytes-per-incoming-chunk-overhead The test's assumptions about RSS are no longer valid, at least with Fedora 38. Closes: https://github.com/nodejs/node/issues/48490 PR-URL: https://github.com/nodejs/node/pull/48811 Fixes: https://github.com/nodejs/node/issues/48490 Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau --- ...t-net-bytes-per-incoming-chunk-overhead.js | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 test/pummel/test-net-bytes-per-incoming-chunk-overhead.js diff --git a/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js b/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js deleted file mode 100644 index b3613110ab5c54..00000000000000 --- a/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js +++ /dev/null @@ -1,50 +0,0 @@ -// Flags: --expose-gc -'use strict'; - -const common = require('../common'); - -if (process.config.variables.asan) { - common.skip('ASAN messes with memory measurements'); -} - -if (common.isPi) { - common.skip('Too slow for Raspberry Pi devices'); -} - -const assert = require('assert'); -const net = require('net'); - -// Tests that, when receiving small chunks, we do not keep the full length -// of the original allocation for the libuv read call in memory. - -let client; -let baseRSS; -const receivedChunks = []; -const N = 250000; - -const server = net.createServer(common.mustCall((socket) => { - baseRSS = process.memoryUsage.rss(); - - socket.setNoDelay(true); - socket.on('data', (chunk) => { - receivedChunks.push(chunk); - if (receivedChunks.length < N) { - client.write('a'); - } else { - client.end(); - server.close(); - } - }); -})).listen(0, common.mustCall(() => { - client = net.connect(server.address().port); - client.setNoDelay(true); - client.write('hello!'); -})); - -process.on('exit', () => { - global.gc(); - const bytesPerChunk = - (process.memoryUsage.rss() - baseRSS) / receivedChunks.length; - // We should always have less than one page (usually ~ 4 kB) per chunk. - assert(bytesPerChunk < 650, `measured ${bytesPerChunk} bytes per chunk`); -}); From 00cb23af1e9e4d12b475aab619d9c9871235a22f Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Sat, 24 Dec 2022 15:44:11 +0100 Subject: [PATCH 02/10] net: add autoSelectFamily global getter and setter PR-URL: https://github.com/nodejs/node/pull/45777 Reviewed-By: Matteo Collina --- doc/api/cli.md | 10 ++ doc/api/net.md | 46 +++++- lib/net.js | 31 +++- src/node_options.cc | 4 + src/node_options.h | 1 + ...balls.js => test-http-autoselectfamily.js} | 0 ...alls.js => test-https-autoselectfamily.js} | 0 ...net-autoselectfamily-commandline-option.js | 108 ++++++++++++++ ...=> test-net-autoselectfamily-ipv4first.js} | 0 ...eballs.js => test-net-autoselectfamily.js} | 15 +- .../test-net-autoselectfamilydefault.js | 140 ++++++++++++++++++ ...socket-connect-invalid-autoselectfamily.js | 9 ++ 12 files changed, 355 insertions(+), 9 deletions(-) rename test/parallel/{test-http-happy-eyeballs.js => test-http-autoselectfamily.js} (100%) rename test/parallel/{test-https-happy-eyeballs.js => test-https-autoselectfamily.js} (100%) create mode 100644 test/parallel/test-net-autoselectfamily-commandline-option.js rename test/parallel/{test-net-happy-eyeballs-ipv4first.js => test-net-autoselectfamily-ipv4first.js} (100%) rename test/parallel/{test-net-happy-eyeballs.js => test-net-autoselectfamily.js} (91%) create mode 100644 test/parallel/test-net-autoselectfamilydefault.js create mode 100644 test/parallel/test-net-socket-connect-invalid-autoselectfamily.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 83c76711d01ffc..a60ef3929c6feb 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -314,6 +314,15 @@ added: v6.0.0 Enable FIPS-compliant crypto at startup. (Requires Node.js to be built against FIPS-compatible OpenSSL.) +### `--enable-network-family-autoselection` + + + +Enables the family autoselection algorithm unless connection options explicitly +disables it. + ### `--enable-source-maps` + +* {string\[]} + +This property is only present if the family autoselection algorithm is enabled in +[`socket.connect(options)`][] and it is an array of the addresses that have been attempted. + +Each address is a string in the form of `$IP:$PORT`. If the connection was successful, +then the last address is the one that the socket is currently connected to. + ### `socket.bufferSize` + +Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. + +* `value` {boolean} The new default value. The initial default value is `false`. + +## `net.getDefaultAutoSelectFamily()` + + + +Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. + +* Returns: {boolean} The current default value of the `autoSelectFamily` option. + ## `net.createServer([options][, connectionListener])` - -Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. - -* `value` {boolean} The new default value. The initial default value is `false`. - -## `net.getDefaultAutoSelectFamily()` - - - -Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. - -* Returns: {boolean} The current default value of the `autoSelectFamily` option. - ## `net.createServer([options][, connectionListener])` + +Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. + +* Returns: {boolean} The current default value of the `autoSelectFamily` option. + +## `net.setDefaultAutoSelectFamily(value)` + + + +Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. + +* `value` {boolean} The new default value. The initial default value is `false`. + +## `net.getDefaultAutoSelectFamilyAttemptTimeout()` + + + +Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. + +* Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option. + +## `net.setDefaultAutoSelectFamilyAttemptTimeout(value)` + + + +Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. + +* `value` {number} The new default value, which must be a positive number. If the number is less than `10`, + the value `10` is used insted The initial default value is `250`. + ## `net.isIP(input)`