Skip to content

Commit c3a89ff

Browse files
AdamMajerjuanarbol
authored andcommitted
net, dns: socket should handle its output as input
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent a4a079d commit c3a89ff

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/net.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,16 @@ Socket.prototype.connect = function(...args) {
11031103
return this;
11041104
};
11051105

1106+
function socketToDnsFamily(family) {
1107+
switch (family) {
1108+
case 'IPv4':
1109+
return 4;
1110+
case 'IPv6':
1111+
return 6;
1112+
}
1113+
1114+
return family;
1115+
}
11061116

11071117
function lookupAndConnect(self, options) {
11081118
const { localAddress, localPort } = options;
@@ -1145,7 +1155,7 @@ function lookupAndConnect(self, options) {
11451155

11461156
if (dns === undefined) dns = require('dns');
11471157
const dnsopts = {
1148-
family: options.family,
1158+
family: socketToDnsFamily(options.family),
11491159
hints: options.hints || 0
11501160
};
11511161

test/parallel/parallel.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ test-worker-message-port-message-before-close: PASS,FLAKY
5656
# https://github.com/nodejs/node/issues/43446
5757
test-net-connect-reset-until-connected: PASS, FLAKY
5858

59-
[$system==aix]
60-
6159
[$system==ibmi]
6260
# https://github.com/nodejs/node/pull/30819
6361
test-child-process-fork-net-server: SKIP

0 commit comments

Comments
 (0)