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

EAI_AGAIN using alpine #1030

Open
tomer-amir-vonage opened this issue Apr 30, 2019 · 15 comments
Open

EAI_AGAIN using alpine #1030

tomer-amir-vonage opened this issue Apr 30, 2019 · 15 comments
Labels

Comments

@tomer-amir-vonage
Copy link

I am running an express server on AWS Fargate using the node:10.13.0-alpine image.

A few days ago we had an instance crash, and I found this error in its logs:

Error: getaddrinfo EAI_AGAIN ****.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start:js: `cd out; node app.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start:js script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-04-27T11_17_16_680Z-debug.log

Looking online this seems like an alpine issue, but I am not sure, and I am not sure that this is where to fix it, but I was hoping at least for tips on how to fix it for my instance...

Thanks!

@LaurentGoderre
Copy link
Member

Seems that issue is that the DNS failed to resolve. Is this something that randomly happens or is it reproducible?

@tomer-amir-vonage
Copy link
Author

It happened randomly, and I haven't been able to reproduce yet...
It might have been a temporary network issue, but I would still like to know if there's a way to prevent this from crashing the whole server and just fail that specific request... but this might not be a question for this repo 😕

@LaurentGoderre
Copy link
Member

Is DNS.js your own file or part of express?

@tomer-amir-vonage
Copy link
Author

I am pretty sure that dns.js is a core nodejs module for handling DNS

@LaurentGoderre
Copy link
Member

Can you try this?

docker run --rm -it node:10.13.0-alpine node -pe 'require("dns").lookup("www.amazon.com",function(){console.dir(arguments)})'

@cesco69
Copy link

cesco69 commented May 8, 2019

It happens to me also after upgrading from node:10.15.1-alpine to node:12.1.0-alpine .
In my case I set host resolution in docker-compose:

...
extra_hosts:
      - "SQL:192.168.1.xxx"
...

@yujintang
Copy link

alipina will EAI_AGAIN or delays about 5s, using stretch-slim i solved this problem!

@qubyte
Copy link

qubyte commented Sep 17, 2020

I may be wrong, but it looks like this issue from a different alpine based image: gliderlabs/docker-alpine#255

@nitram509
Copy link

nitram509 commented Nov 1, 2021

We faced the same issue and figured out the reason.
Especially under high load and in Kubernetes environments, random DNS lookup errors occur.

The Callstack Diagram below, explains what happens.
In this example, the application is trying to make an HTTP connection to www.example.org/.
Hence, the IP must be lookup up, so the lib/dns.js (part of Node) wraps a Node's engine function,
which then does the actual lookup, via calling getaddrinfo().
The latter depends on the dynamically linked libc.
And there's the problem: Alpine's musl libc does not fully support all features DNS resolving, e.g. when you use multiple DNS servers or search orders.

There are two possible solutions:
A) Don't use minimal base images, which don't fully support libc features (e.g. Alpine), but rather switch to Debian, Ubuntu, Ubi, etc. "slim" variants.
B) When building the Node.js engine binary, statically link the libc's getaddrinfo() into the binary. This would not use dynamic linked musl libc code.

PS: I guess coding/fixing the musl libc implementation likely will not happen (assuming, as I see contradicting goals)

Callstack

@m4heshd
Copy link

m4heshd commented Mar 4, 2022

Getting EAI_AGAIN error even with bullseye. 🤦🏻‍♂️

@muzuiget
Copy link

I also got this issue in combination: docker image alpine:3.15, and alpine repo nodejs package, an error reason: getaddrinfo EAI_AGAIN raise randomly.

So, current solution is stop using alpine image?

@wang-xiaowu
Copy link

wang-xiaowu commented Aug 12, 2022

i have one question
if i use debian-slim
should i install gcc/g++ manually?

@vahidsabet
Copy link

Hi same issue running nodejs:alpine inside Docker:

cause: Error: getaddrinfo EAI_AGAIN api.telegram.org
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
errno: -3001,
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'api.telegram.org'
}
}

@abnerwei
Copy link

abnerwei commented Sep 3, 2024

alpine v3.18.2 still catch getaddrinfo EAI_AGAIN

@LaurentGoderre
Copy link
Member

I don't think this is specifically a problem with Node. This thread from the Moby project might help:

moby/moby#32106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

13 participants