Commit 8d4262525dd for nodejs
commit 8d4262525ddb8a3cfc5e7ba3d929246300872a10
Author: Filip Skokan <panva.ip@gmail.com>
Date: Wed Oct 14 11:37:36 2026 +0200
test: reserve both families for local port test
Reserve the source port with a dual-stack listener and keep it open
until the destination server is listening. This prevents choosing an
occupied IPv6 port or letting the destination reuse the source port.
Refs: https://github.com/nodejs/reliability/issues/1686
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66722
Refs: https://github.com/nodejs/reliability/issues/1687
Refs: https://github.com/nodejs/reliability/issues/1690
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
diff --git a/test/parallel/test-net-autoselectfamily-local-port.js b/test/parallel/test-net-autoselectfamily-local-port.js
index ba3ae408dfb..ef13d8a7082 100644
--- a/test/parallel/test-net-autoselectfamily-local-port.js
+++ b/test/parallel/test-net-autoselectfamily-local-port.js
@@ -13,12 +13,17 @@ TCP.prototype.connect6 = function() {
};
const reserved = createServer();
-reserved.listen(0, '127.0.0.1', common.mustCall(() => {
+// Reserve both address families: an IPv4-only reservation may choose a port
+// that is already in use by an IPv6-only socket.
+reserved.listen(0, '::', common.mustCall(() => {
const localPort = reserved.address().port;
- reserved.close(common.mustCall(() => {
- const server = createServer(common.mustCall((socket) => socket.end()));
- server.listen(0, '127.0.0.1', common.mustCall(() => {
- const port = server.address().port;
+ const server = createServer(common.mustCall((socket) => socket.end()));
+ // Keep the reservation until the destination listens so it cannot take
+ // the source port that the client is about to use.
+ server.listen(0, '127.0.0.1', common.mustCall(() => {
+ const port = server.address().port;
+ assert.notStrictEqual(port, localPort);
+ reserved.close(common.mustCall(() => {
const connection = createConnection({
host: 'example.org',
port,