How to Fix the getaddrinfo EAI_AGAIN Error
Find which lookup failed and where, then fix the resolver or retry, with Python, Node.js and cURL code.
Updated
TL;DR
getaddrinfo EAI_AGAIN means your system's DNS lookup failed for now: the name server did not answer or reported a server failure, so no connection started. Fix the DNS settings where the code runs, such as a container's or WSL's resolv.conf, then retry with a short backoff.
What EAI_AGAIN looks like in each client
The host name shows which lookup failed. curl prints the same text for every failed lookup.
| Where | What you see |
|---|---|
| Node.js http.get() | Error: getaddrinfo EAI_AGAIN example.com |
| Node.js fetch() and its cause | TypeError: fetch failed ... [cause]: Error: getaddrinfo EAI_AGAIN example.com |
| axios through an HTTP proxy, as console.log prints it | AxiosError: getaddrinfo EAI_AGAIN proxy.geonode.io |
| npm 11 | npm error request to https://registry.npmjs.org/left-pad failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org |
| Python requests on glibc Linux (Debian, Ubuntu) | Failed to resolve 'example.com' ([Errno -3] Temporary failure in name resolution) |
| curl, site name | curl: (6) Could not resolve host: example.com |
| curl, proxy host name | curl: (5) Could not resolve proxy: proxy.geonode.io |
Why this happens
Your computer asked a DNS server for an address and got no usable reply.
On Linux, getaddrinfo() returns EAI_AGAIN when the listed name servers give no reply or answer SERVFAIL. Node.js passes the code on unchanged, before it opens any connection to a proxy or website.
Diagnose your EAI_AGAIN first
These checks show which name failed, where the lookup runs and whether its DNS server can be reached.
Open a website in a browser on this computer; if it loads but the script fails, DNS is broken where the script runs.
Check the host after EAI_AGAIN; if it is the proxy's, the proxy was never reached; if it is the site, your client resolved it itself.
On Linux, run getent ahosts with the failing host where the code runs; exit code 2 means getaddrinfo() fails there too.
Disconnect your VPN and rerun the script; if the error stops, the VPN breaks DNS for the script, a known WSL problem.
Print /etc/resolv.conf where the code runs; with no nameserver line, glibc asks the local machine, which answers only if it runs a DNS server.
Solutions ranked by effectiveness
Fix the resolver first, add retries for short outages, then check that sites are resolved on the proxy side.
- Most common fix
Give the environment a working resolver
Applies when lookups fail every time inside a container, WSL or cluster; give that environment a resolver it can reach.
Docker: add --dns with a reachable server, or a dns: list in Compose.
For every container at once, start dockerd with --dns or its daemon.json dns key.
WSL on a VPN: set generateResolvConf=false and put the VPN's DNS server first in resolv.conf.
Kubernetes: if kubectl get pods -n kube-system -l k8s-app=kube-dns shows no running CoreDNS, deploy it.
- Check next
Retry temporary lookups with backoff
Applies when EAI_AGAIN comes and goes. All three tabs retry after 1, 2 and 4 seconds; Python and Node.js retry only that code, but curl's --retry also repeats missing names.
import socket, time, urllib.error, urllib.request proxy = "http://USERNAME:PASSWORD@proxy.geonode.io:9000" opener = urllib.request.build_opener(urllib.request.ProxyHandler({"http": proxy})) for attempt in range(4): try: print("HTTP", opener.open("http://example.com/", timeout=30).status) break except urllib.error.URLError as err: if getattr(err.reason, "errno", None) != socket.EAI_AGAIN or attempt == 3: raise time.sleep(2 ** attempt) - For developers
Let the proxy resolve site names
Applies when the error names the website even though you set a proxy. Your client looked the site up itself, so hand the name to the proxy instead.
Pass the proxy in code; Node.js http and fetch ignore HTTP_PROXY by default.
For SOCKS5, write socks5h:// instead of socks5://, so the proxy resolves each site.
Remove the site's domain from NO_PROXY, which sends matching hosts around the proxy.
Stop the EAI_AGAIN from coming back
Settings and habits that keep one slow or missing DNS server from stopping a whole job.
Set options timeout:2 attempts:3 in resolv.conf, or Docker's --dns-opt, so a dead server is skipped sooner.
List two or three name servers run by different providers; glibc uses at most three.
Reuse connections with a keep-alive agent; each new connection, not each request, needs a lookup.
Resolve the proxy host at startup and exit with a clear message if that fails.
Log err.code and err.hostname for every network error, so DNS failures stand apart from timeouts and resets.
Related errors
Learn more
FAQ
Same exit IP after a retry
On sticky ports, a retry within the session leaves from the same residential IP.


