Error: getaddrinfo ENOTFOUND

走远了吗. 提交于 2019-12-07 00:28:41

问题


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.


回答1:


I met the same issue and solved it!

try:

sudo vi /etc/hosts

and add:

127.0.0.1 localhost

to hosts




回答2:


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.



来源:https://stackoverflow.com/questions/44009848/error-getaddrinfo-enotfound

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!