Ubuntu 24.04 LTS
Linux sendol-Ubuntu 6.8.0-38-generic #38-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:25:01 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
net
What steps will reproduce the bug?
The code located in ./test/parallel/test-net-socket-connect-without-cb.js
'use strict';
const common = require('../common');
// This test ensures that socket.connect can be called without callback
// which is optional.
const net = require('net');
const server = net.createServer(common.mustCall(function(conn) {
conn.end();
server.close();
})).listen(0, common.mustCall(function() {
const client = new net.Socket();
client.on('connect', common.mustCall(function() {
client.end();
}));
const address = server.address();
if (!common.hasIPv6 && address.family === 'IPv6') {
// Necessary to pass CI running inside containers.
client.connect(address.port);
} else {
client.connect(address);
}
}));
Command:
// you should build Node.js from source first
./out/Release/node ./test/parallel/test-net-socket-connect-without-cb.js
How often does it reproduce? Is there a required condition?
Always, but your computer should be configured to allow usage of IPv6 and you shouldn't have (IPv6 loopback address) localhost pair in your hosts file.
What is the expected behavior? Why is that the expected behavior?
Do not print anything and normally terminate.
What do you see instead?
Following error
node:events:495
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -3007,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'localhost'
}
Additional information
I think this happens because socket.connect(options[, connectListener]) uses options.host as the host the socket should connect to, while the return of server.address() has keys of address, family, and port. As address.host does not exist on the client.connect(address); in the test code, it seems that it tries to connect the default host 'localhost'.
I'm not sure which one of test code and net module should be fixed, but I can try to fix this and make PR if it is decided.
Version
v23.0.0-pre
Platform
Subsystem
net
What steps will reproduce the bug?
The code located in
./test/parallel/test-net-socket-connect-without-cb.js
Command:
How often does it reproduce? Is there a required condition?
Always, but your computer should be configured to allow usage of IPv6 and you shouldn't have
(IPv6 loopback address) localhost
pair in your hosts file.What is the expected behavior? Why is that the expected behavior?
Do not print anything and normally terminate.
What do you see instead?
Following error
Additional information
I think this happens because
socket.connect(options[, connectListener])
usesoptions.host
as the host the socket should connect to, while the return ofserver.address()
has keys ofaddress
,family
, andport
. Asaddress.host
does not exist on theclient.connect(address);
in the test code, it seems that it tries to connect the default host'localhost'
. I'm not sure which one of test code andnet
module should be fixed, but I can try to fix this and make PR if it is decided.