What's the cause of the error 'getaddrinfo EAI_AGAIN'?

Javascriptnode.jsError HandlingDnsShopify

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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

Solution 3 - Javascript

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

Solution 4 - Javascript

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).

Solution 5 - Javascript

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

127.0.0.1	localhost

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

127.0.0.1	localhost

Solution 6 - Javascript

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.

Solution 7 - Javascript

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.

Solution 8 - Javascript

@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!!

Solution 9 - Javascript

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

Solution 10 - Javascript

I was having this issue on docker-compose. Turns out I forgot to add my custom isolated named network to my service which couldn't be found.

TLDR; Make sure, in your compose file, you have your custom-networks defined on both services that need to talk to each other.

My error looked like this: Error: getaddrinfo EAI_AGAIN minio-service. The error was coming from my server's backend when making a call to the minio-service using the minio-service hostname. This tells me that minio-service's running service, was not reachable by my server's running service. The way I was able to fix this issue is I changed the minio-service in my docker-compose from this:

  • docker-compose.yml
version: "3.8"

# ...

services:
  server:
    # ...
    networks:
      my-network:
    # ...
  minio-service:
    # ... (missing networks: section)

# ...

networks:
  my-network:

To include my custom isolated named network, like this:

  • docker-compose.yml
version: "3.8"

# ...

services:
  server:
    # ...
    networks:
      my-network:
    # ...
  minio-service:
    # ...   
    networks:
      my-network:
    # ...

# ...

networks:
  my-network:

More details on docker-compose networking can be found here.

Solution 11 - Javascript

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.

Solution 12 - Javascript

Had same error when trying to install a NPM package from the WSL.

npm ERR! request to https://registry.npmjs.org/serverless-python-requirements failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org

Replaced the existing DNS servers specified in resolv.conf editing it with

sudo nano /etc/resolv.conf

and the specifying public DNS servers from Google

nameserver 8.8.8.8
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

Solution 13 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomasReggiView Question on Stackoverflow
Solution 1 - JavascriptbastienView Answer on Stackoverflow
Solution 2 - JavascriptxerqView Answer on Stackoverflow
Solution 3 - JavascriptDiego P. SteinerView Answer on Stackoverflow
Solution 4 - JavascriptmikemaccanaView Answer on Stackoverflow
Solution 5 - JavascriptRadhe9254View Answer on Stackoverflow
Solution 6 - JavascriptMartin BramwellView Answer on Stackoverflow
Solution 7 - JavascriptJohn RixView Answer on Stackoverflow
Solution 8 - JavascriptMateenView Answer on Stackoverflow
Solution 9 - JavascriptmbessonView Answer on Stackoverflow
Solution 10 - JavascriptJohnView Answer on Stackoverflow
Solution 11 - JavascriptIgor JankovićView Answer on Stackoverflow
Solution 12 - JavascriptRicardo stands with UkraineView Answer on Stackoverflow
Solution 13 - JavascriptDaniel DanieleckiView Answer on Stackoverflow