---
title: "Connection refused or timed out: what each error tells you | Proofline"
description: "A refused connection means a host answered and nothing accepted the port; a timeout means nothing answered at all."
url: https://proofline.sh/learn/connection-refused-vs-timeout/
---

[Learning center](/learn/)

# Connection refused or timed out: what each error tells you

A refused connection means a host answered and nothing accepted the port; a timeout means nothing answered at all. Refused points at the dependency's process, listener or port, so look at the target. A timeout points at the path: a security group, firewall rule, network ACL or route that dropped the SYN. Unreachable errors mean something on the way reported that it has no route.

Network outages The Proofline team November 23, 2026 6 min read

## Three errors from one connect call

Every TCP client opens its connection with `connect()`, and the error your library logs is usually the errno that call returned, wrapped in the runtime's own words. The three families mean different things:

| errno | Text | What happened to the SYN |
| --- | --- | --- |
| `ECONNREFUSED` | Connection refused | A host answered with a reset |
| `ETIMEDOUT` | Connection timed out | No answer arrived before the retries ran out |
| `EHOSTUNREACH` | Host is unreachable | An ICMP error or a failed next hop was reported |
| `ENETUNREACH` | Network is unreachable | No route to the destination network |

The `connect(2)` page defines `ECONNREFUSED` as finding "no one listening on the remote address", and `ETIMEDOUT` as a timeout while attempting the connection, adding that the server may be too busy to accept new connections. [connect(2)](https://man7.org/linux/man-pages/man2/connect.2.html) · [errno(3)](https://man7.org/linux/man-pages/man3/errno.3.html)

A reset comes from TCP itself. When a segment arrives for a connection that does not exist, the receiving host sends a reset, so a host that is up with no process bound to the port refuses straight away. Firewalls that reject rather than drop also send one. [RFC 9293, reset generation](https://www.rfc-editor.org/rfc/rfc9293.html)

A timeout is slower. Linux retransmits the initial SYN `tcp_syn_retries` times, 6 by default, which takes about 127 seconds before `connect()` gives up. Most clients set a shorter connect timeout of their own, so the log shows the library's timeout message, not the kernel's. [tcp(7)](https://man7.org/linux/man-pages/man7/tcp.7.html)

Unreachable errors depend on ICMP. RFC 1122 treats destination unreachable codes 0, 1 and 5 (network, host, source route failed) as soft errors that TCP may report only when the connection times out, and codes 2 to 4 as hard errors that abort it. Linux follows that pattern: after retries fail it reports either `ETIMEDOUT` or the last error it received, which is how a host-unreachable ICMP turns into `EHOSTUNREACH` after a long wait. [RFC 1122, ICMP messages](https://www.rfc-editor.org/rfc/rfc1122.html) · [tcp(7) error handling](https://man7.org/linux/man-pages/man7/tcp.7.html)

## Why a cloud network usually times out

On AWS, security groups contain allow rules only. Traffic that no rule allows gets no reply, and network ACLs, which are stateless and can deny, behave the same way for denied traffic. The EC2 troubleshooting guide lists security group rules, route tables and network ACLs as the checks for a "Connection timed out" error. Google Cloud's VPC firewall ends with an implied deny ingress rule that applies when no allow rule matches. So in a cloud VPC a blocked port almost always shows up as a timeout, while a refused connection tells you the packet got through to a host. [Security group rules](https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html) · [Network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html) · [Connection timed out](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html) · [Cloud NGFW implied rules](https://cloud.google.com/firewall/docs/firewalls)

A refusal can still come from something in between. A load balancer, proxy or sidecar that is listening on the address can answer for a backend that is gone, so check which address you actually connected to.

## Observe it without changing anything

Run the test from where the failing client runs: the same container, task or pod, not your laptop. Resolve the name first so you know which address you are testing; a stale DNS answer that points at a decommissioned host looks like either error. [getaddrinfo failures](/learn/getaddrinfo-temporary-failure-name-resolution/)

```
getent hosts orders-db.example.internal
nc -vz -w 5 10.0.12.34 5432
```

`-z` only checks for a listener without sending data, `-v` prints the result and `-w 5` limits the wait to five seconds. A refusal returns at once; a drop waits the full five seconds. [nc(1)](https://man.openbsd.org/nc.1)

If you can reach the dependency's host, check that something listens on the port and on which address. A service bound to `127.0.0.1` refuses connections that arrive on the VPC address.

```
ss -lnt 'sport = :5432'
```

`ss -l` lists listening sockets, `-n` keeps addresses numeric and `-t` limits output to TCP. [ss(8)](https://man7.org/linux/man-pages/man8/ss.8.html)

For a timeout on AWS, read the rules on both ends and the subnet routes. VPC Flow Logs, if enabled, record `REJECT` for traffic a security group or network ACL refused. [describe-security-groups](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html) · [Flow log records](https://docs.aws.amazon.com/vpc/latest/userguide/flow-log-records.html)

```
aws ec2 describe-security-groups \
  --profile PROFILE --region REGION --group-ids DEPENDENCY_SECURITY_GROUP_ID \
  --query 'SecurityGroups[0].IpPermissions[].{from:FromPort,to:ToPort,groups:UserIdGroupPairs[].GroupId,cidrs:IpRanges[].CidrIp}' \
  --output json --no-cli-pager
```

On Google Cloud, list the firewall rules that apply to the network and compare targets and source ranges with the client's address and tags. [gcloud compute firewall-rules list](https://cloud.google.com/sdk/gcloud/reference/compute/firewall-rules/list)

```
gcloud compute firewall-rules list --project PROJECT --filter 'network:NETWORK'
```

## Decision table

| Client sees | First place to look |
| --- | --- |
| Refused, instantly | The target host: is the process running, bound to this address and port? |
| Refused, only via a load balancer | The load balancer's listener and its healthy targets |
| Timed out after the client's connect timeout | Security groups, firewall rules, network ACLs, routes |
| Host or network unreachable | Routes and the next hop: subnet route table, VPN or peering |
| Connects, then fails later | Not this guide: TLS, authentication or the application |

A connect that succeeds but takes seconds is a different symptom. If the dependency's accept queue is full, Linux drops the SYN and the client's retransmission eventually gets in. [Listen queue overflow](/learn/listen-queue-overflow-dependency/)

## A worked example with two outcomes

This example is illustrative. The fictional `checkout` service logs failures calling `orders` at `orders.example.internal`, which resolves to 10.0.12.34, on port 8080.

In the first outcome, `nc -vz -w 5 10.0.12.34 8080` from a `checkout` task prints a refusal immediately. On the `orders` host, `ss -lnt 'sport = :8080'` returns nothing: the process restarted after a crash and has not finished starting. The path is fine. The fix belongs to `orders`.

In the second outcome, the same `nc` waits five seconds and times out. `ss` on the `orders` host shows the listener on `0.0.0.0:8080`. The `orders` security group allows port 8080 from `sg-0aa1`, and the new `checkout` tasks run in `sg-0bb2`. Flow logs on the `orders` interface show `REJECT` from the new tasks' addresses. The dependency is healthy; the rule is missing. [Only new tasks time out](/learn/dependency-timeouts-only-from-new-tasks/)

## Limits

A successful `nc` shows only that TCP opens. A database at its connection limit, an expired certificate or a bad credential still fail after the handshake. Runtimes rename errors: some print `ECONNREFUSED` verbatim, others print "connection refused" or their own exception type, so look for the underlying errno in the cause chain. A timeout in your library may also be a read or request timeout, not a connect timeout; check which phase timed out before reading this table. Flow logs are delayed and must have been enabled beforehand. For the overall method of separating your release from the dependency, see the [runtime dependency failures hub](/learn/runtime-dependency-failures/).

## Questions

### Why does a blocked port in AWS time out instead of refusing?

Security groups have no deny rules and send nothing back for traffic they do not allow, so the client keeps retransmitting its SYN until its connect timeout fires. Network ACL denies look the same from the client.

### Can a refused connection come from a firewall?

Yes. A firewall configured to reject sends a reset or an ICMP error instead of dropping. Cloud security groups and the default Google Cloud ingress behavior do not, so inside a VPC a refusal usually comes from a host or a proxy.

### Why did the error say host unreachable after two minutes?

TCP treats ICMP host unreachable as a soft error and keeps retrying. When the retries run out, Linux reports the last error it received in place of a plain timeout.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Dependency timeouts only from new ECS tasks or Cloud Run revisions](/learn/dependency-timeouts-only-from-new-tasks/)
    
    Network outages The Proofline team November 20, 2026 9 min read
    
-   ### [Slow connects to a dependency that looks idle: a full listen queue](/learn/listen-queue-overflow-dependency/)
    
    Network outages The Proofline team November 23, 2026 5 min read
