---
title: "Connection Refused vs Timed Out vs Reset: Find the Failing Layer"
description: "Map refused, timed out, reset and DNS failures to TCP behavior and per-language error text, with nc, curl timing, tcpdump steps and mid-stream disconnects."
url: https://cdnping.org/en/blog/connection-refused-timeout-reset-diff
language: en
published: 2026-10-30
category: "Troubleshooting"
tags: ["TCP","network troubleshooting","curl","tcpdump","API calls"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# Connection Refused vs Timed Out vs Reset: Find the Failing Layer

The difference between connection refused and timed out comes down to whether the other side sent anything back. Refused means your SYN reached the target machine and it immediately answered with an RST, which says "nothing is listening on this port." Timed out means the SYN went out and nothing came back, so the client waited until its timeout expired. Refused usually fails within a few milliseconds to one round trip; timed out takes anywhere from a few seconds to two minutes. A reset is different again: the connection was already established (data may even have been flowing) and one side cut it off with an RST.

If you look at "what packet came back, and how long did it take," the error text from every language and tool fits into one table. This article gives the table first, then the commands to verify it, and finally the case of AI API streaming responses that get reset midway.

## What TCP behavior does each error correspond to?

Counting DNS resolution failure, there are four categories:

| Type | What happens on the network | Typical timing | Where the problem usually is |
| --- | --- | --- | --- |
| DNS failure | No TCP packet is sent; the hostname never resolves to an address | Very fast, or stuck on a DNS timeout (a few seconds) | Local DNS, a misspelled hostname, the proxy's DNS settings |
| refused | SYN sent, RST received | About one round trip, often within tens of milliseconds | Host is up but no service on the port; a firewall configured to REJECT; or the local proxy port isn't open |
| timed out (connect phase) | SYN sent, no response at all | Until the client's timeout; Linux default retransmission runs about two minutes | Host unreachable, firewall DROP, broken routing, IP blocked |
| reset | Connection established, then an RST arrives | Unpredictable: right after the handshake or tens of seconds into the transfer | Server process crashed or closed the connection, load balancer/proxy idle timeout, interference from a middlebox, TLS-layer mismatch |

There is also a "read timeout," which is easy to confuse with a connect timeout: TCP connected and the request was sent, but no response arrived within the configured time. It tells you the network layer works and the problem is a slow server or a stalled intermediate proxy. So first work out whether you have a connect timeout or a read timeout, because the investigation differs.

## How do the error messages map across languages and tools?

The same TCP behavior looks different in different places. The table lists the common original text so you can search your own logs for it:

| Type | Node.js | Python requests / urllib3 | curl | Chrome |
| --- | --- | --- | --- | --- |
| DNS failure | `ENOTFOUND`, `EAI_AGAIN` | `NameResolutionError`, `Name or service not known`, `Temporary failure in name resolution` | `(6) Could not resolve host` | `ERR_NAME_NOT_RESOLVED` |
| refused | `connect ECONNREFUSED 1.2.3.4:443` | `[Errno 111] Connection refused` (on Windows `[WinError 10061]`) | `(7) Failed to connect ... Connection refused` | `ERR_CONNECTION_REFUSED` |
| connect timeout | `connect ETIMEDOUT` | `ConnectTimeout`, `[Errno 110] Connection timed out` (Windows `10060`) | `(28) Connection timed out after ... milliseconds` | `ERR_CONNECTION_TIMED_OUT` |
| read timeout | Your own timeout fires, `AbortError` | `ReadTimeout`, `Read timed out` | `(28) Operation timed out ... with N bytes received` | The page spins forever |
| reset | `ECONNRESET`, `socket hang up` | `[Errno 104] Connection reset by peer`, `Connection aborted`, `RemoteDisconnected` (Windows `10054`) | `(56) Recv failure: Connection reset by peer`; during the handshake it is `(35)` | `ERR_CONNECTION_RESET` |

Two more notes:

- `EAI_AGAIN` and `Temporary failure in name resolution` mean "DNS didn't answer for now," which is different from `ENOTFOUND`, where the name doesn't exist. Retrying the former may succeed; retrying the latter is pointless.
- Node.js `socket hang up` doesn't necessarily mean the peer sent an RST. The peer may have sent a FIN and closed normally while the client was still waiting for a response. Investigate it together with `ECONNRESET`.

## How do you confirm which one it is from the command line?

SDKs sometimes wrap errors so the original text is hidden. In that case, look directly from the command line.

### Step 1: use nc to see whether the port is reachable

```bash
nc -vz -w 5 api.example.com 443
```

- An immediate `succeeded` / `open`: the TCP layer is fine; look higher up at TLS and HTTP.
- An immediate `Connection refused`: the peer or a middlebox sent back an RST.
- A `timed out` after the full 5 seconds: packets are being dropped.

If you're used to ping, keep in mind that ping uses ICMP and says nothing definite about whether TCP port 443 is reachable. For details, see [Ping fails but the website opens? ICMP ping vs tcping](/en/blog/ping-vs-tcping-port-latency).

### Step 2: use curl's timing breakdown to see which phase stalls

```bash
curl -sS -o /dev/null --connect-timeout 10 -m 60 \
  -w 'dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} code=%{http_code}\n' \
  https://api.example.com/
```

How to read it:

- `dns` is very large, or the command fails right away with `(6)`: a resolution problem.
- `tcp` is 0 with `(7)`: refused. `tcp` is 0 and it fails with `(28)` after `--connect-timeout`: connect timeout.
- `tcp` is normal, `tls` is 0 and the error is `(35)` or `SSL_ERROR_SYSCALL`: TCP connected but the TLS handshake was interrupted. See [Troubleshooting curl SSL_ERROR_SYSCALL and TLS handshake timeouts](/en/blog/ssl-error-syscall-tls-handshake-fail).
- `tls` is normal but `ttfb` is very large: the network works and the slowness is on the server or gateway.

You can also compare these timings with the "first connection" figure from the browser test on the [cdnping homepage](/en).

### Step 3: capture SYN and RST with tcpdump

If the first two steps can't settle it, capture packets:

```bash
sudo tcpdump -ni any 'host 1.2.3.4 and tcp port 443 and (tcp[tcpflags] & (tcp-syn|tcp-rst) != 0)'
```

Start the request in another terminal, then read the output:

- Only your own outgoing `[S]`, repeated several times, with no reply: DROP, which corresponds to a timeout.
- An `[S]` immediately followed by the peer's `[R.]`: refused.
- `[S]` and `[S.]` complete the handshake, then an `[R]` shows up after some time: reset. Check which direction the RST came from and you'll know who cut the connection.

An RST whose source address is the target IP doesn't necessarily mean the target server sent it. A firewall or proxy in the path can also forge an RST with the peer's address. If the RST arrives much faster than the normal round-trip time, it was most likely sent by a device closer to you on the path.

## How do firewalls, proxies, and load balancers change what you see?

Middleboxes can make the same underlying problem show up as different errors:

- Firewall DROP vs REJECT: both mean "connection not allowed," but DROP silently discards packets so the client sees a timeout, while REJECT replies with an RST or ICMP unreachable so the client sees refused. So refused doesn't always mean "the service isn't running"; it can be a firewall policy.
- Local proxy: if `HTTPS_PROXY` is set, the client is actually connecting to the proxy address. When the proxy software isn't running, you'll see errors like `ECONNREFUSED 127.0.0.1:7890` and the target server is never contacted. Checking whether the IP and port in the error are what you expected can save a lot of time. (Port 7890 is a common default for local proxy clients in China.)
- Idle timeouts on proxies and load balancers: when a connection has had no data for a long time, the middlebox reclaims it. If the client then writes to it, it receives an RST and reports `ECONNRESET`. Reusing a stale connection from a connection pool that has already been reclaimed is one of the most common sources of this error, and it shows up as "intermittent, fine after one retry."
- MTU problems: when small handshake packets get through but large packets are dropped, the connection establishes normally, then the request goes out and hangs until the read timeout. You won't see refused or reset. For the investigation, see [What MTU should I use? Troubleshooting HTTPS hangs caused by large-packet black holes](/en/blog/mtu-mss-blackhole-https-hang).

## What commonly causes a streaming response to be reset midway?

When calling large model APIs, you often hit `ECONNRESET`, `Connection reset by peer`, or an SDK-wrapped "stream disconnected" halfway through the output. Since the connection has been up for a while, DNS and connect-phase problems are ruled out, and the cause narrows to a few categories:

1. Timeout settings in an intermediate layer. A self-hosted Nginx, a cloud load balancer, or a CDN may impose a read timeout or total-duration limit on a single request. Long replies, long model "thinking" time, or long stretches with no output make it easy to hit. The telltale sign is that the disconnect happens at a fairly fixed point, for example always near a certain number of seconds.
2. Proxy client or network switching. A local proxy restart, a node switch, or a laptop changing networks will break any long-lived connection in progress.
3. The server closing the connection. Server overload, a release restart, or a per-request timeout can also close the connection directly. In this case many people are usually affected at the same time.
4. Wrong buffering configuration. An intermediate layer buffers the SSE stream, so the client receives no data for a long time and trips its own timeout, which looks like a dropped stream. See [Troubleshooting SSE streaming output that is buffered and returned all at once](/en/blog/sse-streaming-buffered-behind-cdn-nginx).

How to tell them apart: record how many seconds after the request started each disconnect happens. If the values cluster around one fixed number, check the intermediate-layer timeouts first. If they are randomly distributed, check the network and proxy. If all kinds of requests drop during the same period, check the server status first. The specific Nginx and CDN settings are listed in full in [LLM streaming output cut off midway: troubleshooting SSE disconnects on Nginx, CDNs, and load balancers](/en/blog/llm-sse-streaming-disconnect-proxy).

## Rule out a server-side outage first

Before you spend half an hour capturing packets on your own machine, spend one minute checking whether the other side is already having problems:

- Open the [cdnping API status page](/en/status) to see the results of probes against the target API endpoint from the Cloudflare edge every 5 minutes, or go to [Is it down?](/en/down) to see official status pages and reports from other users.
- On the [cdnping homepage](/en), run a "first connection" test directly (it includes DNS and the TLS handshake) and compare it with the result of curl on your own machine. If the browser can connect and your program can't, the problem is most likely in the program's proxy or DNS configuration.

Here is an example: in cdnping's edge probes from the Cloudflare Denver node between 08:40 and 10:05 UTC on 2026-10-17 (242 probe records in the window), the Kimi (Moonshot AI) open platform endpoint had an availability of about 94.4%, with a p50 latency of 375 ms and a p95 of 1125 ms, while the other endpoints, both in China and abroad, were at 100% availability in the same window. The window is only a bit over an hour and does not represent long-term behavior; it only illustrates that occasional failures and latency tails can come from the server or the network path rather than from your local setup. For how the data is collected, see [Methodology](/en/methodology).

## A checklist you can follow

1. Read the original error text and classify it with the tables above: DNS, refused, connect timeout, read timeout, or reset.
2. Look at the IP and port in the error and confirm whether it's the target server or a local proxy address.
3. Check [/status](/en/status) and [/down](/en/down) to rule out a server-side incident.
4. Use `nc -vz` to check the port, and `curl -w` timing to determine whether it stalls at DNS, TCP, TLS, or the first byte.
5. If it's still unclear, use tcpdump to look at the direction and timing of SYN, SYN-ACK, and RST.
6. For a reset: record when the disconnects happen and decide whether it's a fixed timeout, a network switch, or a server problem; check whether the connection pool's idle-reclaim time is shorter than the middleboxes'.
7. Only after you've established the error is transient should you add retries to your program. Refused and connect timeouts can be retried a limited number of times; read timeouts and mid-stream disconnects need to consider idempotency and billing. For how to write it, see [How to write LLM API retries: exponential backoff with jitter and retry budgets](/en/blog/llm-api-retry-exponential-backoff-jitter).

If you use a command-line tool such as Claude Code, the full layer-by-layer checklist is in [Troubleshooting Claude Code connection timeouts and errors: a four-layer network checklist](/en/blog/claude-code-connection-troubleshooting).
