Skip to content

net.connect fails looking up localhost when offline (node-v0.x-archive/issues/25489 duplicate) #11320

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

Closed
RobertDiebels opened this issue Feb 12, 2017 · 8 comments
Labels
dns Issues and PRs related to the dns subsystem. windows Issues and PRs related to the Windows platform.

Comments

@RobertDiebels
Copy link

  • Version: Any version since v0.12.2 x64
  • Platform: Windows 10 x64
  • Subsystem: net.connect?

Hi guys,

I have a bug to report which was found via a Karma issue. I don't have the details on exactly what went wrong though I got referred to: nodejs/node-v0.x-archive#25489 as being the cause of the issue.

The Karma issue I started is: karma-runner/karma#2050
I created a Repo for reproduction: https://github.com/RobertDiebels/karma-test

What happened is the following:

  • During a power outage I thought I would write some Unit-tests
  • For this I used karma run
  • This failed to execute and threw this error:
Error: getaddrinfo ENOENT localhost:9877
    at Object.exports._errnoException (util.js:849:11)
    at errnoException (dns.js:31:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

Steps to reproduce

  • Clone the repo I created above.
  • Unplug from your LAN and disconnect your Wireless adapter
  • Run karma run (Disco inferno!)

If I can or should provide some extra information please notify me and I'll gladly provide it.

@mscdex mscdex added dns Issues and PRs related to the dns subsystem. windows Issues and PRs related to the Windows platform. labels Feb 12, 2017
@sam-github
Copy link
Contributor

Why do you think a domain name lookup should suceed when you are offline?

If you want to your tests to work disconnected, don't rely on domain names, use addresses.

@sam-github
Copy link
Contributor

Put another way, this is a host configuration issue. Unix systems usually add an entry for 'localhost' into /etc/hosts so it can be resolved offline, I'm not sure what Windows does typically, but node defers to the system to resolve addresses.

@bnoordhuis
Copy link
Member

I suspect it's because node does the lookup with the AI_ADDRCONFIG flag set. The archived issue also hints at that.

On Windows, it makes 'localhost' unresolvable unless there is at least one non-local IPv4- or IPv6-capable network interface. (At least, I think that is how it works - don't quote me on it.)

FWIW, Chromium unconditionally disables AI_ADDRCONFIG on Windows: https://chromium.googlesource.com/chromium/src/net/+/e80513ca05b7aae855297e09748c76686bdad9ab/dns/host_resolver_proc.cc#156

On Linux, it seems to disable it when no non-local interfaces exist: https://chromium.googlesource.com/chromium/src/net/+/e80513ca05b7aae855297e09748c76686bdad9ab/dns/host_resolver_proc.cc#184

I could be persuaded that setting AI_ADDRCONFIG is the wrong thing at least some of the time but I'm wary of changing it and finding out we broke the world. It's not something our CI will catch.

@RobertDiebels
Copy link
Author

RobertDiebels commented Feb 13, 2017

@sam-github first of all. I didn't even want to have to create an issue regarding node. I was referred here by a developer from karma. As they stated it was an issue with node. Which is the archived one I linked.

I do not want to use domain-names for my tests. I want to be able to run my tests without being connected to a network adapter.

I could go back to the guys from Karma and say that this isn't an issue with Node if that's what you want. I have no idea of the underlying Karma code nor of the underlying Node code, and at the moment I have no desire to acquire that information.

I just acted on the suggestions the guys from Karma and yourself gave me. Which were:

  1. Notify the people at Node that this is still a relevant issue on the archived node issue.
  2. Create a new issue if you want the archived one to be solved.

That's all.

Also what you suggested concerning the host-name addresses is what they suggested as a work-around not an actual fix.

@bnoordhuis
Copy link
Member

@RobertDiebels A possible fix for karma is to make calls to net.connect(), http.request(), etc. with { hints: 0 } to skip the AI_ADDRCONFIG flag.

@yaacovCR
Copy link

While this (RFC 3493?) is all hashed out, my fix is to use a small package that overrides net.connect (!!!) to null the dns.ADDRCONFIG flag. Once require'ed, all packages will just work offline.

I published this work-around to npm as node-offline-localhost. I am still trying to work out how to best formally test this; I need a test suite that can spin up node.js environments with network connectivity that can be manipulated intra-tests. Thoughts?

My preference, btw, is to enable this only in a development environment. The package also supports detection of existing non-local network interfaces and nulling dns.ADDRCONFIG as appropriate; this can be done at start-up or call time.

@bnoordhuis: A terrible idea? A terrible idea whose time has come? Comments are welcome.

@bzoz
Copy link
Contributor

bzoz commented May 23, 2017

Since changing this would probably lead to a lot of new issues and there is a userland fix, should we close the issue?

@bnoordhuis
Copy link
Member

Yes, let's do that. Can reopen if necessary.

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

No branches or pull requests

6 participants