Skip to content

Commit

Permalink
net, dns: socket should handle its output as input
Browse files Browse the repository at this point in the history
As a consequence of #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: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
AdamMajer authored and juanarbol committed Oct 3, 2022
1 parent a4a079d commit c3a89ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,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;
Expand Down Expand Up @@ -1145,7 +1155,7 @@ function lookupAndConnect(self, options) {

if (dns === undefined) dns = require('dns');
const dnsopts = {
family: options.family,
family: socketToDnsFamily(options.family),
hints: options.hints || 0
};

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,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]

[$system==ibmi]
# https://github.com/nodejs/node/pull/30819
test-child-process-fork-net-server: SKIP
Expand Down

0 comments on commit c3a89ff

Please sign in to comment.