docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

EAI_AGAIN using alpine

Open tomer-amir-vonage opened this issue 5 years ago • 13 comments

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!

tomer-amir-vonage avatar Apr 30 '19 08:04 tomer-amir-vonage

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

LaurentGoderre avatar Apr 30 '19 14:04 LaurentGoderre

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 😕

tomer-amir-vonage avatar Apr 30 '19 14:04 tomer-amir-vonage

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

LaurentGoderre avatar Apr 30 '19 15:04 LaurentGoderre

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

tomer-amir-vonage avatar Apr 30 '19 16:04 tomer-amir-vonage

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)})'

LaurentGoderre avatar Apr 30 '19 17:04 LaurentGoderre

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

cesco69 avatar May 08 '19 16:05 cesco69

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

yujintang avatar Jun 21 '19 07:06 yujintang

I may be wrong, but it looks like this issue from a different alpine based image: https://github.com/gliderlabs/docker-alpine/issues/255

qubyte avatar Sep 17 '20 19:09 qubyte

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

nitram509 avatar Nov 01 '21 10:11 nitram509

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

m4heshd avatar Mar 04 '22 17:03 m4heshd

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?

muzuiget avatar May 18 '22 09:05 muzuiget

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

wang-xiaowu avatar Aug 12 '22 03:08 wang-xiaowu

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' } }

vahidsabet avatar Jul 16 '23 15:07 vahidsabet