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 · 54 comments

Comments

Projects
None yet
@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

This comment has been minimized.

Copy link
Member

benjamingr commented Feb 25, 2016

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

This comment has been minimized.

Copy link
Author

T94T commented Feb 25, 2016

Yes. url and host are just placeholders.

@silverwind

This comment has been minimized.

Copy link
Contributor

silverwind commented Feb 25, 2016

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

This comment has been minimized.

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

This comment has been minimized.

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 dns labels Feb 25, 2016

@bnoordhuis

This comment has been minimized.

Copy link
Member

bnoordhuis commented Feb 26, 2016

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

@T94T

This comment has been minimized.

Copy link
Author

T94T commented Feb 26, 2016

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

This comment has been minimized.

Copy link
Member

bnoordhuis commented Feb 26, 2016

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

@T94T

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

bnoordhuis commented Feb 26, 2016

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

bnoordhuis commented Feb 27, 2016

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

@bnoordhuis bnoordhuis closed this Feb 27, 2016

@jacmet

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

bnoordhuis commented Mar 14, 2016

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

@T94T

This comment has been minimized.

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

This comment has been minimized.

Copy link

lightswitch05 commented Aug 5, 2016

What versions of node was this fix included in?

@SoundBot

This comment has been minimized.

Copy link

SoundBot commented Aug 30, 2016

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

This comment has been minimized.

Copy link
Member

bnoordhuis commented Aug 30, 2016

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

@denghuiquan

This comment has been minimized.

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

This comment has been minimized.

Copy link

ArsalanDotMe commented Dec 14, 2016

@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

This comment has been minimized.

Copy link

denghuiquan commented Dec 14, 2016

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

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Oct 2, 2017

@catamphetamine it is always easy to blame someone. This will not help anyone though. If you like to improve the situation please open a pull request.

@catamphetamine

This comment has been minimized.

Copy link

catamphetamine commented Oct 2, 2017

@BridgeAR it is always easy to blame a non-contributor for pointing out things that the supporting team fails to address and is ignorant of by saying he's not opening any pull requests.

@gibfahn

This comment has been minimized.

Copy link
Member

gibfahn commented Oct 2, 2017

As @joyeecheung mentioned about 10 months ago, changing this message will cause breakage in the community.

Current consensus seems to be that changing this will affect more users than it helps.

If you actually have any new information please do point it out, but being insulting is unlikely to achieve anything.

@refack

This comment has been minimized.

Copy link
Member

refack commented Oct 2, 2017

Can someone explain, please, how to actually solve this issue now? Update node? Linux? Some package?
I'm on Ubuntu 16.04 LTS now. Still having the issue.

Thank you.

@Vasiliy-Bondarenko can you provide more information?
Which version of node are you using?
Can you post a sample code snippet?
You can also explicitly tell node's DNS to look for an IPv4 address with:

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

This comment has been minimized.

Copy link

catamphetamine commented Oct 3, 2017

Current consensus seems to be that changing this will affect more users than it helps.

that will do

being insulting is unlikely to achieve anything.

it actually is, you're just not seeing the bigger picture

@bnoordhuis

This comment has been minimized.

Copy link
Member

bnoordhuis commented Oct 3, 2017

It will just make you get ignored, or, if you're too jerkass or meme-spammy, banned.

@kslearn

This comment has been minimized.

Copy link

kslearn commented Nov 24, 2017

same error come
355

@adjavaherian

This comment has been minimized.

Copy link

adjavaherian commented Nov 28, 2017

I'm seeing a similar issue and remarkably, was even able to reproduce it with nslookup on high sierra randomly.

$ nslookup x.x.net
Server:		10.x.x.x
Address:	10.x.x.x#53

** server can't find x.x.net: NXDOMAIN

$ nslookup x.x.net
Server:		10.x.x.x
Address:	10.x.x.x#53

Non-authoritative answer:
x.x.net	canonical name = x.x.x.net.
Name:	x.x.x.net
Address: 10.x.x.x

My Node ENOTFOUND is on v8.4.0 and happens intermittently while resolving bower package dependencies for a project, so I'm actually using request through the bower npm package. Is there a way to force request to use IPv4 globally at runtime? I'm guessing the glibc that ships with osx high sierra hasn't been patched yet?

@camstuart

This comment has been minimized.

Copy link

camstuart commented Dec 19, 2017

Hello everyone.

I also get this error. Originally I was using node 8.9.3 and this problem was occurring spasmodically. I upgraded to 9.2.0 and still, on occasion the problem arises.

My process is a long running 'service' that does http POSTs to another nodejs service.
The http library I am using is: axios 0.16.2

And the error: getaddrinfo ENOTFOUND

Does anyone have a solution or workaround? I'm almost at the point where I need to do an external system call to curl..... not my preference as I'm sure you can imagine

@blakecodes

This comment has been minimized.

Copy link

blakecodes commented Jan 19, 2018

Found this exact error because the host was not defined in the server configuration.

Was attempting a call on localhost, but localhost wasn't defined to link to 127.0.0.1

@johnanisere

This comment has been minimized.

Copy link

johnanisere commented Feb 6, 2018

I get this Error Error: getaddrinfo ENOTFOUND api.remotehost.com api.remotehost.com:80
when I try to do this on google cloud functions

(req,res,next)=>{
       let options={
           method:'POST',
           uri: config.uri,
           form:{
               username:req.body.username,
               to:req.body.to,
               message:req.body.message
           },
           headers:{  apikey:req.headers.apikey,
                      'Accept':"Application/json"   
                     },
           family: 4,
           port: 80
       }
       
       request(options)
       .then((_)=>res.status(200).send(_))
       .catch((e)=>res.status(500).send(e))
}

It works fine on localhost ,I only get this on google cloud functions

I tried adding this { family: 6 } as suggested above and I started getting this new error Error: getaddrinfo EAI_AGAIN api.remotehost.com:80

@efranco2012

This comment has been minimized.

Copy link

efranco2012 commented Mar 14, 2018

johnanisere,

I get the similar error with Cloud Functions. How did you resolve this?

@johnanisere

This comment has been minimized.

Copy link

johnanisere commented Mar 14, 2018

@efranco2012

This comment has been minimized.

Copy link

efranco2012 commented Mar 14, 2018

So, I did find out the problem. You'll need to enable billing at https://google.firebase.com for your project to make external API requests. If billing is not enabled you'll get an error.

Stated at the bottom of this article.
https://www.menubar.io/firebase-functions-sending-emails/

@soualid

This comment has been minimized.

Copy link

soualid commented Apr 5, 2018

Just in case it might help someone. We had the same issue using 9.10.1 when our application was under heavy load, we resolved it by caching DNS values with https://github.com/devswede/dns-cache (we think it was related to nodejs/node-v0.x-archive#7729).

@rohan-deshpande

This comment has been minimized.

Copy link

rohan-deshpande commented Apr 13, 2018

Have also noticed this happening at random times in a CLI app which makes multiple calls to different APIs, will try out the DNS cache and see if that fixes it.

@julienvincent

This comment has been minimized.

Copy link

julienvincent commented Jun 14, 2018

Is there a system (OS) level fix for this issue yet? I am running node v10 in docker and am unable to resolve certain hostnames due to this.

Need a way to fix this without touching application code (which the solutions above do)

@andig

This comment has been minimized.

Copy link

andig commented Jun 24, 2018

Same problem here trying to request data from the Fritzbox router (fritz.box) unsing node v8.11.2 About 30% of the requests will fail:

{ Error: getaddrinfo ENOTFOUND fritz.box fritz.box:49000
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'fritz.box',
  host: 'fritz.box',
  port: '49000' }
@brunomanzo

This comment has been minimized.

Copy link

brunomanzo commented Sep 9, 2018

Any workaround for this? Started to get it locally randomly, I hard coded some ips but it is annoying

@IzaGz

This comment has been minimized.

Copy link

IzaGz commented Oct 10, 2018

anyone pls help!

@waqaramjad

This comment has been minimized.

Copy link

waqaramjad commented Feb 11, 2019

i am facing the same issue i am using firebase with react native expo app
any one tell me is it possible with firebase spark plane

FetchError: request to https://exp.host/--/api/v2/push/send failed, reason: getaddrinfo ENOTFOUND exp.host exp.host:443

@intelliot

This comment has been minimized.

Copy link

intelliot commented Feb 13, 2019

Seeing the same issue in a long-running service. Restarting the service resolves it (temporarily).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.