Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: getaddrinfo ENOTFOUND

Tags:

node.js

axios

I have a simple Node.js bot that makes an HTTP request each second to a rest API.

If the returned data is right then I construct an URL where I HTTP POST.

Everything works alright but after ~4-5hrs of running I got this error

0|server   | error:  Error: getaddrinfo ENOTFOUND www.rest-api.com www.rest-api.com:443
0|server   |     at errnoException (dns.js:28:10)
0|server   |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)

Can someone explain to me why this has happened?

After I restart my server everything got working.

I'm using axios to make the http requests.

like image 972
Anderson Avatar asked May 16 '17 19:05

Anderson


Video Answer


1 Answers

The symptom is that the remote address cannot be resolved.

The cause could be many things. First, try to see if it's node specific by trying to resolve the address directly:

$ nslookup www.rest-api.com

Or:

$ dig www.rest-api.com

If that doesn't work, you've got a connectivity problem. It could be anything. Try looking at how long your DHCP lease lasts if you are using DHCP.

However if that does work fine but your node application still fails, you might be running into this: https://github.com/nodejs/node/issues/5436 , which is a bug in an underlying library. You can implement the workaround mentioned in that thread, which is specifying the IP version family through the following parameter { family: 4 } as a part of your request options.

like image 94
arboreal84 Avatar answered Sep 22 '22 18:09

arboreal84