Skip to content

Commit 3b06eea

Browse files
committed
net, dns: Socket should handle its output as input
As a consequence of nodejs#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 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: nodejs#44003
1 parent 7f7a899 commit 3b06eea

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/net.js

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

1101+
function socketToDnsFamily(family) {
1102+
switch (family) {
1103+
case 'IPv4':
1104+
return 4;
1105+
case 'IPv6':
1106+
return 6;
1107+
}
1108+
1109+
return family;
1110+
}
11011111

11021112
function lookupAndConnect(self, options) {
11031113
const { localAddress, localPort } = options;
@@ -1140,7 +1150,7 @@ function lookupAndConnect(self, options) {
11401150

11411151
if (dns === undefined) dns = require('dns');
11421152
const dnsopts = {
1143-
family: options.family,
1153+
family: socketToDnsFamily(options.family),
11441154
hints: options.hints || 0
11451155
};
11461156

test/parallel/parallel.status

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ test-crypto-dh-stateless: SKIP
3737
test-crypto-keygen: SKIP
3838

3939
[$system==solaris] # Also applies to SmartOS
40-
# https://github.com/nodejs/node/pull/43054
41-
test-net-socket-connect-without-cb: SKIP
42-
test-net-socket-ready-without-cb: SKIP
43-
test-tcp-wrap-listen: SKIP
4440
# https://github.com/nodejs/node/issues/43446
4541
test-net-connect-reset-until-connected: PASS, FLAKY
4642
# https://github.com/nodejs/node/issues/43457
@@ -65,12 +61,6 @@ test-worker-message-port-message-before-close: PASS,FLAKY
6561
# https://github.com/nodejs/node/issues/43446
6662
test-net-connect-reset-until-connected: PASS, FLAKY
6763

68-
[$system==aix]
69-
# https://github.com/nodejs/node/pull/43054
70-
test-net-socket-connect-without-cb: SKIP
71-
test-net-socket-ready-without-cb: SKIP
72-
test-tcp-wrap-listen: SKIP
73-
7464
[$system==ibmi]
7565
# https://github.com/nodejs/node/pull/30819
7666
test-child-process-fork-net-server: SKIP

0 commit comments

Comments
 (0)