176

My server threw this today, which is a Node.js error I've never seen before:

Error: getaddrinfo EAI_AGAIN my-store.myshopify.com:443
    at Object.exports._errnoException (util.js:870:11)
    at errnoException (dns.js:32:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)

I'm wondering if this is related to the DynDns DDOS attack which affected Shopify and many other services today. Here's an article about that.

My main question is what does dns.js do? What part of node is it a part of? How can I recreate this error with a different domain?

Kimon
  • 17
  • 1
  • 7
ThomasReggi
  • 42,912
  • 63
  • 199
  • 343

13 Answers13

180

If you get this error with Firebase Cloud Functions, this is due to the limitations of the free tier (outbound networking only allowed to Google services).

Upgrade to the Flame or Blaze plans for it to work.

enter image description here

bastien
  • 2,447
  • 1
  • 10
  • 20
138

EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.

My main question is what does dns.js do?

  • The dns.js is there for node to get ip address of the domain(in brief).

Some more info: http://www.codingdefined.com/2015/06/nodejs-error-errno-eaiagain.html

xerq
  • 1,477
  • 1
  • 5
  • 15
13

If you get this error from within a docker container, e.g. when running npm install inside of an alpine container, the cause could be that the network changed since the container was started.

To solve this, just stop and restart the container

docker-compose down
docker-compose up

Source: https://github.com/moby/moby/issues/32106#issuecomment-578725551

Diego P. Steiner
  • 1,316
  • 10
  • 14
  • I have a suspected issue where the network is reset on the host, and then the containers seem to have DNS errors thereafter. Is there some way to configure the containers to survive this *without* stopping them? – trademark May 14 '21 at 20:21
3

The OP's error specifies a host (my-store.myshopify.com). The error I encountered is the same in all respects except that no domain is specified.

My solution may help others who are drawn here by the title "Error: getaddrinfo EAI_AGAIN"

I encountered the error when trying to serve a NodeJs & VueJs app from a different VM from where the code was developed originally.

The file vue.config.js read :

 module.exports = {
   devServer: {
     host: 'tstvm01',
     port: 3030,
   },
 };

When served on the original machine the start up output is :

App running at:
- Local:   http://tstvm01:3030/ 
- Network: http://tstvm01:3030/

Using the same settings on a VM tstvm07 got me a very similar error to the one the OP describes:

 INFO  Starting development server...
 10% building modules 1/1 modules 0 activeevents.js:183                              
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo EAI_AGAIN
    at Object._errnoException (util.js:1022:11)
    at errnoException (dns.js:55:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

If it ain't already obvious, changing vue.config.js to read ...

 module.exports = {
   devServer: {
     host: 'tstvm07',
     port: 3030,
   },
 };

... solved the problem.

Martin Bramwell
  • 1,554
  • 1
  • 14
  • 33
2

This is the issue related to hosts file setup. Add the following line to your hots file In Ububtu: /etc/hosts

127.0.0.1   localhost

In windows: c:\windows\System32\drivers\etc\hosts

127.0.0.1   localhost
Radhe9254
  • 163
  • 1
  • 10
2

I started getting this error (different stack trace though) after making a trivial update to my GraphQL API application that is operated inside a docker container. For whatever reason, the container was having difficulty resolving a back-end service being used by the API.

After poking around to see if some change had been made in the docker base image I was building from (node:13-alpine, incidentally), I decided to try the oldest computer science trick of rebooting... I stopped and started the docker container and all went back to normal.

Clearly, this isn't a meaningful solution to the underlying problem - I am merely posting this since it did clear up the issue for me without going too deep down rabbit holes.

halfer
  • 18,701
  • 13
  • 79
  • 158
John Rix
  • 4,931
  • 3
  • 35
  • 39
2

As xerq's excellent answer explains, this is a DNS timeout issue.

I wanted to contribute another possible answer for those of you using Windows Subsystem for Linux - there are some cases where something seems to be askew in the client OS after Windows resumes from sleep. Restarting the host OS will fix these issues (it's also likely restarting the WSL service will do the same).

mikemaccana
  • 81,787
  • 73
  • 317
  • 396
1

@xerq pointed correctly, here's some more reference http://www.codingdefined.com/2015/06/nodejs-error-errno-eaiagain.html

i got the same error, i solved it by updating "hosts" file present under this location in windows os

C:\Windows\System32\drivers\etc

Hope it helps!!

Mateen
  • 1,353
  • 1
  • 16
  • 24
0

I had a same problem with AWS and Serverless. I tried with eu-central-1 region and it didn't work so I had to change it to us-east-2 for the example.

Igor Janković
  • 5,210
  • 5
  • 26
  • 45
0

Enabled Blaze and it still doesn't work?

Most probably you need to set .env from the right path, require('dotenv').config({ path: __dirname + './../.env' }); won't work (or any other path). Simply put the .env file in the functions directory, from which you deploy to Firebase.

Daniel Danielecki
  • 3,527
  • 3
  • 29
  • 41
0

In my case the problem was the docker networks ip allocation range, see this post for details

mbesson
  • 300
  • 9
-4

If you are not get that at localhost either production, that means you must upgrade your plan due to the limitations of the free tier

-17

updating the npm to latest fixes this problem for me.

npm install npm@latest

this issue is related to your network connectivity. hence can be temporary. on a stable internet connection this issue was hardly observed.

anerjan
  • 37
  • 8
  • 27
    How updating the package manager could fix an error which is not related to the package manager ? – FF_Dev Aug 31 '17 at 10:39
  • 4
    In @anerjan's defence, it can occur when running `npm install` and I imagine the time it took to stop update and restart he'd connected back to the internet. – Rambatino Jun 20 '18 at 21:20