Skip to content

Error explained

Error: connect ETIMEDOUT

ETIMEDOUT means a connection or request got no answer within the time allowed. Unlike a refusal, something is silently dropping the traffic, or the server is too slow.

4 min read12 sectionsUpdated

On this page

Key points

  • Connect timeouts point to the network: firewalls, security groups, wrong IPs.
  • Read timeouts point to slow servers that accepted the connection.
  • Always set explicit timeouts; defaults can be minutes or infinite.
  • Retry idempotent calls with backoff and jitter.

Connect timeout vs read timeout

TypeMeaningTypical cause
Connect timeoutThe TCP handshake never completedFirewall dropping packets, wrong IP, host down
Read / response timeoutConnected, but no response in timeSlow query, overloaded server, long GC pause

Diagnosing

bash
nc -vz -w 5 api.internal 443          # connect within 5 s?
curl -sv --connect-timeout 5 --max-time 30 https://api.internal/health
traceroute api.internal                # where packets stop (if ICMP is allowed)

If the connect step hangs, check security groups, network ACLs and firewall rules for the source address, and that the IP is correct (stale DNS after a migration is common). If connecting works but the response times out, open a trace of the slow request on the server side to see where the time goes; see 504 Gateway Timeout.

Set timeouts deliberately

javascript
// fetch (Node 18+): overall time limit
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });

// axios: response timeout
await axios.get(url, { timeout: 5000 });
python
import requests
requests.get(url, timeout=(3.05, 10))   # (connect, read) seconds

Retry only idempotent requests (GET, PUT with the same body, requests with an idempotency key), use exponential backoff with jitter, and cap the attempts, or retries multiply load during an outage.

Catching it in production

Timeouts show as long, failing client spans in traces, often all to one dependency. Alert on the dependency’s error rate and p99 latency rather than on each timeout.

VitalRix error tracking groups exceptions recorded on OpenTelemetry spans into issues with counts, first and last seen, affected endpoints and versions, and marks an issue as regressed if it comes back after being resolved. Alert rules on error rate per service or endpoint route the problem to the right team before customers report it.

When the address is wrong

After a migration, stale DNS or a hard-coded IP can send traffic to an address that no longer answers, which looks exactly like a firewall drop. Log the resolved IP alongside the error, check it against the current record, and lower TTLs before planned moves. See DNS monitoring.

Find which timeout fired

ETIMEDOUT means a network operation did not finish in time. Which operation matters: connecting, or waiting for a response.

PhaseTypical causeWhat to check
DNS lookupSlow or unreachable resolverdig the host from the same machine
TCP connectFirewall dropping packets, wrong IP, server overloadednc -vz host port, security groups
TLS handshakeOverloaded server, middlebox issuesopenssl s_client timing
Waiting for the responseSlow upstream, long query, deadlockUpstream traces and logs
javascript
// separate the connect timeout from the overall timeout, so the error says which one fired
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(new Error('response timeout after 10s')), 10_000);
try {
  const res = await fetch('https://api.example.com/orders', { signal: controller.signal });
  console.log(res.status);
} finally { clearTimeout(timer); }

Fixes that hold

  • Set explicit timeouts on every outbound call, shorter than the timeout of whatever calls you.
  • Retry idempotent requests with backoff and jitter; never retry a payment without an idempotency key.
  • Reuse connections (keep-alive agents) so you do not pay the connect cost on every call.
  • Watch the upstream: a rising rate of ETIMEDOUT to one host is an incident at that host. Alert on it with an API check, and see ECONNRESET and ECONNREFUSED for the related errors.

Frequently asked questions

Should I just raise the timeout?

Only if the work is legitimately slow. Long timeouts tie up workers and make outages worse. Fix the slow part, or move it out of the request.

Why do timeouts happen only under load?

Pools and queues fill up, so requests wait before any work starts. Check saturation: connection pools, worker counts, CPU.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.