Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require("net").connect() doesn't work from version 17.0.0 and above #43776

Closed
ArkadiuszMichalski opened this issue Jul 11, 2022 · 3 comments
Closed
Labels
net Issues and PRs related to the net subsystem.

Comments

@ArkadiuszMichalski
Copy link

Version

17.0.0 and above

Platform

Microsoft Windows NT 10.0.22000.0 x64

Subsystem

net

What steps will reproduce the bug?

I use old MozRepl extension for Firefox: https://github.com/bard/mozrepl
This is the TCP server listening for localhost on port 4242. It works correct now on my setup, I can connect to it with PuTTY.

From Node.js side I used this code:

var net = require("net");
var socket = net.connect({"host": "localhost", "port": "4242"});

It worked for years, unfortunately after upgrading to Node.js 18.5.0 it stopped. I get a message:

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED ::1:4242
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 4242
}

Node.js v18.5.0

I started testing each version backwards and the last one that works is Node.js 16.9.1. So the problem started to appear from the version Node.js 17.0.0 (inclusive).

How often does it reproduce? Is there a required condition?

Each time with newer versions starting from Node.js 17.0.0.

What is the expected behavior?

Works also in new versions of Node.js.

What do you see instead?

Error, as given above

Additional information

Any tips on what the problem could be?

@theanarkh
Copy link
Contributor

It looks like you listen to the ipv4 address but connect to ipv6 address. Maybe you can try this: net.connect({"host": "localhost", "port": "4242", family: 4});.

@ArkadiuszMichalski
Copy link
Author

@theanarkh
Yes, setting family: 4 solves the problem. Lookse like the default behavior had to change some time ago and now we have to set it additionally. Thanks for the quick help.

If it doesn't need to be documented anywhere then please close this issue.

@VoltrexKeyva VoltrexKeyva added the net Issues and PRs related to the net subsystem. label Jul 11, 2022
@bnoordhuis
Copy link
Member

It was mentioned in the changelog for v17.0.0. The relevant commit is 1b2749e. I'll go ahead and close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants