[PATCH] net, dns: socket should handle its output as input
authorAdam Majer <amajer@suse.de>
Mon, 1 Aug 2022 11:16:23 +0000 (13:16 +0200)
committerJérémy Lal <kapouer@melix.org>
Thu, 4 Aug 2022 15:32:43 +0000 (16:32 +0100)
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
Gbp-Pq: Topic build
Gbp-Pq: Name getaddrinfo_no_iface.patch

lib/net.js
test/parallel/parallel.status

index 06b318b3faa2d233a092e8926fb4c65e5c331164..7f3c51e5fe86856df8cd9f09f46211e88ae7df83 100644 (file)
@@ -1072,6 +1072,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;
@@ -1114,7 +1124,7 @@ function lookupAndConnect(self, options) {
 
   if (dns === undefined) dns = require('dns');
   const dnsopts = {
-    family: options.family,
+    family: socketToDnsFamily(options.family),
     hints: options.hints || 0
   };
 
index c8401933e9d12621e2992592021eff48f4f7a6c0..24c8035bf92a088e0a0a66620874f040b270f400 100644 (file)
@@ -82,10 +82,6 @@ test-crypto-keygen: SKIP
 test-debug-args: PASS,FLAKY
 
 [$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
@@ -110,12 +106,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