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

http.get returns "getaddrinfo ENOTFOUND" error #5436

Closed
T94T opened this issue Feb 25, 2016 · 81 comments
Closed

http.get returns "getaddrinfo ENOTFOUND" error #5436

T94T opened this issue Feb 25, 2016 · 81 comments
Labels
dns Issues and PRs related to the dns subsystem. http Issues or PRs related to the http subsystem.

Comments

@T94T
Copy link

T94T commented Feb 25, 2016

Hi all,
I'm trying to fix following problem since five days.
When I'm doing a

or

  • http.get(options, cb);

there's this error coming back:

HTTP 5021: SOCKET ERROR: getaddrinfo ENOTFOUND _host_ _host_:80 Error: getaddrinfo ENOTFOUND _url_ _url_:80
    at errnoException (dns.js:26:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
Got error: getaddrinfo ENOTFOUND _host_ _host_:80
NET 5021: destroy undefined
NET 5021: destroy
NET 5021: close
NET 5021: close handle
NET 5021: destroy
NET 5021: already destroyed, fire error callbacks
NET 5021: emit close
HTTP 5021: CLIENT socket onClose
HTTP 5021: removeSocket _host_:80: destroyed: true
HTTP 5021: HTTP socket close

When doing a https request to google.com:
Got error: connect ENETUNREACH 2a00:1450:400a:806::1014:443 - Local (:::0)

I can definitely say it's NOT a DNS or a PROXY issue.

What I testet so far:

  • changed hosts file, so no dns lookup is required
    
  • changed resolv.conf to use other DNS servers
    
  • **curl and wget requests do work**
    
  • **ping to destination host works**
    
  • reinstalled complete system
    
  • same node.js code works on a raspbian system
    

node.js sample code:

var http = require('http');
var options = {
  host: '_host_',
  port: 80,
  path: '/'
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);

  res.on("data", function(chunk) {
    console.log("BODY: " + chunk);
  });
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});
  • Version: v5.5.0
  • Platform: Linux buildroot 4.1.15 armv6l (raspberrypi)
@benjamingr
Copy link
Member

Just to be clear, you're not actually doing http.get("http://url/", cb); but rather http.get("http://www.google.com/", cb); or some other website that exists - right?

Also, if you could try previous versions of Node and see if they work for you it would be very appreciated.

@T94T
Copy link
Author

T94T commented Feb 25, 2016

Yes. url and host are just placeholders.

@silverwind
Copy link
Contributor

getaddrinfo is by definition a DNS issue. Does dig host or nslookup host work? Does dns.lookup(host, console.log) work? Can you post the domain?

@T94T
Copy link
Author

T94T commented Feb 25, 2016

dig is not available for buildroot. nslookup is working and gives me the ip address back. I tested lots of different domains (ex. www.hackaday.com)

@T94T
Copy link
Author

T94T commented Feb 25, 2016

and yes, dns.lookup(host, console.log) works and the returned ip address is correct.

@mscdex mscdex added http Issues or PRs related to the http subsystem. dns Issues and PRs related to the dns subsystem. labels Feb 25, 2016
@bnoordhuis
Copy link
Member

What does dns.lookup(host, {hints: dns.ADDRCONFIG|dns.V4MAPPED}, console.log) print?

@T94T
Copy link
Author

T94T commented Feb 26, 2016

{ [Error: getaddrinfo ENOTFOUND host]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'host' }

@bnoordhuis
Copy link
Member

Am I right that it works with {hints:0}? What happens with {hints:dns.ADDRCONFIG} and {hints:dns.V4MAPPED}?

@T94T
Copy link
Author

T94T commented Feb 26, 2016

  • {hints:0}

'x.x.x.x' 4

  • {hints:dns.ADDRCONFIG}

'x.x.x.x' 4

  • {hints:dns.V4MAPPED}
{ [Error: getaddrinfo ENOTFOUND host]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'host' }

x.x.x.x is the correct IP returned.

@bnoordhuis
Copy link
Member

Thanks. You didn't mention what version of glibc you have installed but you're probably hitting a bug in that library. www.hackaday.com is a good example - it's a CNAME for hackaday.com and older glibc versions didn't handle AI_V4MAPPED for such records.

As a workaround, try http.get({ family: 4, ... }, cb), that tells node not to use AI_V4MAPPED. Use { family: 6 } if you want an IPv6 connection.

@T94T
Copy link
Author

T94T commented Feb 27, 2016

I'm using uclibc 1.0.12. At the moment I'm compiling buildroot with standard glibc. Will tell you if something has changed.
Setting the family to 4 is working. 6 is giving me back the known errors.

So, current workaround will be this:

var options = {
  host: '_host_',
  family: 4,
  port: 80,
  path: '/'
};
http.get(options, cb);

@T94T
Copy link
Author

T94T commented Feb 27, 2016

I cannot compile buildroot with standard glibc. There are too many errors.
So for now, above workaround will be the best solution for me.

@bnoordhuis
Copy link
Member

Glad it's working for you now. I'll close the issue.

@jacmet
Copy link

jacmet commented Mar 11, 2016

FYI, this was caused by uClibc-ng not handling AI_V4MAPPED correctly and is now fixed:
http://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/commit/?id=3c1457161e5206c2d576ab25d350a139511c096d

@T94T
Copy link
Author

T94T commented Mar 11, 2016

Hi Peter,

I just saw your message regarding the uClibc "bug". Thanks a lot!!!!! Will
try to rebuild and test it tomorrow.

Regards and have a nice weekend,
Michael

2016-03-11 13:00 GMT+01:00 Peter Korsgaard notifications@github.com:

FYI, this was caused by uClibc-ng not handling AI_V4MAPPED correctly and
is now fixed:

http://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/commit/?id=3c1457161e5206c2d576ab25d350a139511c096d


Reply to this email directly or view it on GitHub
#5436 (comment).

@jacmet
Copy link

jacmet commented Mar 11, 2016

You're welcome. Notice that there hasn't been any new uclibc-ng releases with this fix and it hasn't been integrated into the Buildroot yet. I'll most likely do so this weekend.

@T94T
Copy link
Author

T94T commented Mar 11, 2016

I noticed it before and thought to include the current rev version. But
now, I will wait until your release the new official version. Thanks a lot
again. Greets from Liechtenstein.

2016-03-11 21:02 GMT+01:00 Peter Korsgaard notifications@github.com:

You're welcome. Notice that there hasn't been any new uclibc-ng releases
with this fix and it hasn't been integrated into the Buildroot yet. I'll
most likely do so this weekend.


Reply to this email directly or view it on GitHub
#5436 (comment).

@bnoordhuis
Copy link
Member

/cc @indutny - perhaps lib/dns.js should only set AI_V4MAPPED when family == 6?

@T94T
Copy link
Author

T94T commented Mar 14, 2016

I just downloaded the newest buildroot and compiled it. My issue is now
fixed. Again, thanks a lot!
uclibc version 1.0.13 has now fixed the http.get issue.

2016-03-11 21:02 GMT+01:00 Peter Korsgaard notifications@github.com:

You're welcome. Notice that there hasn't been any new uclibc-ng releases
with this fix and it hasn't been integrated into the Buildroot yet. I'll
most likely do so this weekend.


Reply to this email directly or view it on GitHub
#5436 (comment).

@lightswitch05
Copy link

What versions of node was this fix included in?

@SoundBot
Copy link

workaround doesn't work for me. Node v6.5.0, MacOS 10.11.6

Error: getaddrinfo ENOTFOUND http://google.com http://google.com:80
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

@bnoordhuis
Copy link
Member

You are doing a lookup for 'http://google.com/' when it should be just 'google.com'.

@denghuiquan
Copy link

denghuiquan commented Nov 18, 2016

The same problem as@SoundBot, but is ok local, some time occur in docker.

originalError:
{ Error: getaddrinfo ENOTFOUND xxx.s3-ap-southeast-1.amazonaws.com xxx.s3-ap-southeast-1.amazonaws.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
message: 'getaddrinfo ENOTFOUND xxx.s3-ap-southeast-1.amazonaws.com xxx.s3-ap-southeast-1.amazonaws.com:443',
code: 'NetworkingError',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'xxx.s3-ap-southeast-1.amazonaws.com',
host: 'xxx.s3-ap-southeast-1.amazonaws.com',
port: 443,
region: 'ap-southeast-1',
retryable: true,
 time: 2016-11-18T04:29:58.603Z }

any body has work out the final resolution?

@ArsalanDotMe
Copy link
Contributor

@denghuiquan did you try setting the 'family':4 option as suggested above? I had a similar problem and that fixed it for me. I'm surprised that problem is persisting even at the end of 2016. I was running into this issue on a RPI2 running Raspbian Lite using node v6.9.2.

@denghuiquan
Copy link

specify an usable dns, normally the 8.8.8.8 for the dockerfile would help to this. @ArsalanDotMe

@bnoordhuis
Copy link
Member

Node.js is agnostic, it merely passes on the options to the system resolver. That means you get a lot of control but you also get to deal with libc idiosyncrasies.

@dploeger
Copy link

Okay. And the other applications (like ping) do the same but handle the result for you. Got it. Thanks.

@ahmad-ali14
Copy link

same problem node expres js

@vandersondf
Copy link

i had the same problem when to node work behind proxy.

curl, wget, browse and postman works fine, but node request not.

works for me set proxy.host e proxy.port in axios config.

@gigglegirl
Copy link

gigglegirl commented Sep 2, 2020

I face this issue while running angular protractor in azure pipeline. works fine in local machine but fails in pipeline . Is there any solution to this now ? If not any workarounds please?

image

@bodinsamuel
Copy link

I don't understand how the "fix" proposed by @bnoordhuis in 2016 is still relevant (or not a default option or documented) 😞

@bnoordhuis
Copy link
Member

Easy - if Node.js were to list every random bug you could possibly hit in some third-party library, the documentation would be several times its current size.

@gaoxianglyx
Copy link

same error, in my axios

@Joshfindit
Copy link

Joshfindit commented Mar 3, 2021

Ok, quick question:

Assuming

  • we're using https.get (or a similar library such as axios)
  • the domain is legitimately wrong (let's say user error)
  • we need to catch this error in order to return a notice back to the user

What is the method we should be using?

No combination of try/catch or .then().catch() is working for me

@intelliot
Copy link

Ok, quick question:

Assuming

  • we're using https.get (or a similar library such as axios)
  • the domain is legitimately wrong (let's say user error)
  • we need to catch this error in order to return a notice back to the user

What is the method we should be using?

No combination of try/catch or .then().catch() is working for me

Did you try adding an on(‘error’, ...) listener? https://nodejs.org/api/https.html#https_https_get_options_callback

@himharsh1997
Copy link

request/request#2536

1 similar comment
@himharsh1997
Copy link

request/request#2536

@Eren1415
Copy link

the solution is simple: go to the IDE copilot extension menu and reinstall the extension

martinhauke added a commit to martinhauke/rattl that referenced this issue Oct 19, 2022
Apparently it can happen that requests within node will randomly switch between ipv6 and ipv4 unless one of them is explicitly specified. I have configured ipv4 for now and that seems to fix it.

See also:

* axios/axios#444
* nodejs/node#5436
@akshaykumarsingh2
Copy link

I face this issue while running angular protractor in azure pipeline. works fine in local machine but fails in pipeline . Is there any solution to this now ? If not any workarounds please?

image

Hi @gigglegirl did you get the working solution for this?

@IrisZhang
Copy link

If your use windows and a proxy service, try to set the system hosts file. Add 127.0.0.1 example.com to the file.

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. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests