Skip to content

test-net-socket-connect-without-cb test fails #54111

Open
@sendoru

Description

@sendoru

Version

v23.0.0-pre

Platform

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.testIssues and PRs related to the tests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions