From e6a47e85d22232a353aa14dc0fd1a35227a5f91f Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 4 Aug 2022 01:46:31 +0200 Subject: [PATCH] net, dns: socket should handle its output as input As a consequence of https://github.com/nodejs/node/issues/43014 , server sockets and others, once connected, report string family names. But when feeding these to Socket.connect(), it passes these to host resolution with a string for family while a numeric family is expected internally. This results in wrong hints flags to be set and resolution to fail. As solution, is to add ability to handle both numeric and string family names when doing lookup and connect. Fixes: https://github.com/nodejs/node/issues/44003 PR-URL: https://github.com/nodejs/node/pull/44083 Reviewed-By: Paolo Insogna Reviewed-By: Luigi Pinca --- lib/net.js | 12 +++++++++++- test/parallel/parallel.status | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/net.js b/lib/net.js index 96aea96cbf9a24..845805edb6a507 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1110,6 +1110,16 @@ Socket.prototype.connect = function(...args) { return this; }; +function socketToDnsFamily(family) { + switch (family) { + case 'IPv4': + return 4; + case 'IPv6': + return 6; + } + + return family; +} function lookupAndConnect(self, options) { const { localAddress, localPort } = options; @@ -1152,7 +1162,7 @@ function lookupAndConnect(self, options) { if (dns === undefined) dns = require('dns'); const dnsopts = { - family: options.family, + family: socketToDnsFamily(options.family), hints: options.hints || 0 }; diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 911787a091b5e3..bafd4e16aaf004 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -37,10 +37,6 @@ test-crypto-dh-stateless: SKIP test-crypto-keygen: SKIP [$system==solaris] # Also applies to SmartOS -# https://github.com/nodejs/node/pull/43054 -test-net-socket-connect-without-cb: SKIP -test-net-socket-ready-without-cb: SKIP -test-tcp-wrap-listen: SKIP # https://github.com/nodejs/node/issues/43446 test-net-connect-reset-until-connected: PASS, FLAKY # https://github.com/nodejs/node/issues/43457 @@ -65,12 +61,6 @@ test-worker-message-port-message-before-close: PASS,FLAKY # https://github.com/nodejs/node/issues/43446 test-net-connect-reset-until-connected: PASS, FLAKY -[$system==aix] -# https://github.com/nodejs/node/pull/43054 -test-net-socket-connect-without-cb: SKIP -test-net-socket-ready-without-cb: SKIP -test-tcp-wrap-listen: SKIP - [$system==ibmi] # https://github.com/nodejs/node/pull/30819 test-child-process-fork-net-server: SKIP