Geonode logo
Network errors

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.

WhereWhat you see
Node.js http.get()Error: getaddrinfo EAI_AGAIN example.com
Node.js fetch() and its causeTypeError: fetch failed ... [cause]: Error: getaddrinfo EAI_AGAIN example.com
axios through an HTTP proxy, as console.log prints itAxiosError: getaddrinfo EAI_AGAIN proxy.geonode.io
npm 11npm 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 namecurl: (6) Could not resolve host: example.com
curl, proxy host namecurl: (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.

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

    1. Docker: add --dns with a reachable server, or a dns: list in Compose.

    2. For every container at once, start dockerd with --dns or its daemon.json dns key.

    3. WSL on a VPN: set generateResolvConf=false and put the VPN's DNS server first in resolv.conf.

    4. Kubernetes: if kubectl get pods -n kube-system -l k8s-app=kube-dns shows no running CoreDNS, deploy it.

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

    1. Pass the proxy in code; Node.js http and fetch ignore HTTP_PROXY by default.

    2. For SOCKS5, write socks5h:// instead of socks5://, so the proxy resolves each site.

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

  1. Set options timeout:2 attempts:3 in resolv.conf, or Docker's --dns-opt, so a dead server is skipped sooner.

  2. List two or three name servers run by different providers; glibc uses at most three.

  3. Reuse connections with a keep-alive agent; each new connection, not each request, needs a lookup.

  4. Resolve the proxy host at startup and exit with a clear message if that fails.

  5. Log err.code and err.hostname for every network error, so DNS failures stand apart from timeouts and resets.

Site names travel to the proxyGeonode's HTTP ports take site names in the request; your DNS resolves just the gateway.
Try residential proxies

Related errors

Learn more

FAQ

The operating system could not get an address for the host name just then because its DNS server timed out or failed. The name itself may be valid, so a later lookup can work.

ENOTFOUND is the code Node.js gives EAI_NONAME and EAI_NODATA, usually a name with no address. EAI_AGAIN means the resolver itself failed to answer, so look at the DNS setup before the spelling.

A container resolves names its own way: on the default bridge it gets a copy of the host's resolv.conf, on custom networks it asks Docker's server at 127.0.0.11, and --dns 127.0.0.1 means its own loopback.

They take different paths: dns.lookup() calls getaddrinfo() and reads /etc/hosts, while dns.resolve4() always queries DNS servers on the network and names the failure, such as ETIMEOUT or ESERVFAIL, instead of EAI_AGAIN.

Geonode's docs list IP-based endpoints, which skip DNS resolution, but recommend a host name such as proxy.geonode.io because DNS follows server changes. Use an IP only for a tool that cannot resolve names.

Not by itself. npm shows getaddrinfo EAI_AGAIN registry.npmjs.org when the lookup failed before any request was sent, so check DNS in the shell, container or CI job where npm runs first.

Same exit IP after a retry

On sticky ports, a retry within the session leaves from the same residential IP.