Skip to content
RU

Error: read ECONNRESET (Connection Reset by Peer): Causes and Fixes

What it means: The other end, or something between, abruptly reset an open TCP connection while your code used it.

  1. Note whether it happens on reused connections
  2. Keep server keep-alive longer than the client's
  3. Retry idempotent requests once
  4. Check proxy and load balancer timeouts
  5. Look for crashes on the server

Test your URL now

Pings your host from our server, so you see whether it answers from outside your network.

Check your host & ports →

What ECONNRESET means

ECONNRESET is the operating system error «Connection reset by peer» (errno 104 on Linux). The Node.js docs describe it as: «A connection was forcibly closed by a peer. This normally results from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered via the http and net modules.» (Node.js common system errors). Typical forms:

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons)  { errno: -104, code: 'ECONNRESET', syscall: 'read' }

Error: socket hang up   { code: 'ECONNRESET' }

«socket hang up» is the http client's variant: the http docs list an 'error' event with message 'Error: socket hang up' and code 'ECONNRESET' when the connection closes before a response arrives. Python reports the same condition as ConnectionResetError: [Errno 104] Connection reset by peer, curl as Recv failure: Connection reset by peer.

It is not a refused connection: ECONNREFUSED happens before the connection exists. ECONNRESET means the connection was open and then torn down with a TCP RST.

Causes

CausePatternFix
Reused keep-alive socket the server already closedSporadic, after a few seconds of idle, first request after a pauseClient idle timeout shorter than the server's; retry idempotent calls
Load balancer or proxy idle timeoutFails at a fixed duration (60 s, 100 s, 350 s ...)Align timeouts; send keep-alive probes on long streams
Server process crashed or was killed mid-requestMatches restarts, OOM kills or deploysFix the crash; drain connections on deploy
Server rejects the request bodyLarge uploads; server answers 413 and closesRaise the body limit or send smaller chunks
Firewall or IDS resets the flowSpecific hosts, ports or payloads onlyFind the device that sends the RST with tcpdump
TLS mismatch at the far endReset right after connect, during the handshakeCheck protocol and SNI with openssl s_client

The first row is the classic Node.js case. Since Node.js 19 the default http agent uses keep-alive with a 5-second timeout, and a Node.js server closes idle keep-alive sockets after server.keepAliveTimeout, which defaults to 5000 ms (http docs). When the client picks a pooled socket at the same moment the server closes it, the request is written into a closing connection and fails with ECONNRESET or «socket hang up».

Behind a load balancer or reverse proxy

Every hop has its own idle timeout, and the rule is the same at each one: the side that keeps a connection open longer must be upstream. If a load balancer keeps idle connections to your Node.js app for 60 seconds while the app closes them after 5, the balancer will occasionally send a request into a socket the app just closed, and clients see 502 errors or resets. Raise the app's timeouts above the balancer's:

const server = http.createServer(app);
server.keepAliveTimeout = 65_000; // longer than the balancer's idle timeout
server.headersTimeout   = 66_000; // keep it above keepAliveTimeout

In nginx in front of Node.js, a reset from the app appears in the error log as recv() failed (104: Connection reset by peer) while reading response header from upstream and the client gets a 502. Related proxy-side message: upstream prematurely closed connection.

How to fix it

  1. Log the whole error, including code, syscall and the remote address, and record whether the socket was reused:
    req.on('socket', (s) => console.log('reused:', req.reusedSocket));
    req.on('error', (e) => console.error(e.code, e.syscall, e.message));
  2. If failures hit reused sockets, retry once. Node's http docs suggest exactly this for keep-alive races: retry when req.reusedSocket is true and the error is ECONNRESET, but only for idempotent requests (GET, PUT, DELETE), never a payment POST.
  3. Make the client give up idle sockets first. Set the client agent's idle timeout below the server's keep-alive timeout, or disable keep-alive for a misbehaving upstream: new http.Agent({ keepAlive: false }).
  4. Check the far side. Look for restarts at the failure times (journalctl -u app --since '-1h', kubectl get pods restart counts, dmesg -T | grep -i oom).
  5. Find who sends the RST when it is reproducible:
    tcpdump -ni any 'host 203.0.113.10 and tcp[tcpflags] & tcp-rst != 0'
    A reset that the server never sent was injected by a firewall or middlebox.
  6. Test TLS separately if it fails during connect: openssl s_client -connect api.example.com:443 -servername api.example.com.

How to confirm the fix

# Hammer the endpoint with pauses around the keep-alive timeout
for i in $(seq 1 20); do curl -sS -o /dev/null -w '%{http_code} ' https://api.example.com/health; sleep 5; done
# 200 200 200 ... with no 'Connection reset by peer'

Watch the error rate in application logs for a day: keep-alive races are rare per request but steady under load. To confirm the host and port answer from outside your network, use the ping and port checker.

Related errors

ICMP PingHost availability and latency
Port ScannerOpen TCP port detection
LatencyResponse time in milliseconds
Packet LossPercentage of dropped packets

Why teams trust us

ICMP+TCP
check protocols
14
key ports scanned
3,184
checks in 30 days
3
regions

How it works

1

Enter IP or domain

2

ICMP packets sent

3

Latency & packet loss shown

How Do Ping and Port Scanning Work?

Ping sends ICMP packets to a host and measures response time. Port scanning checks which TCP ports are open and accepting connections — helping diagnose serviceavailability issues.

Configurable Ping

Choose packet count (3, 4, 6, 10). Stats: min/avg/max latency and packet loss.

Common Port Scanner

Check 14 key ports: HTTP, HTTPS, SSH, FTP, SMTP, MySQL, PostgreSQL, and more.

Cloud-Based Check

Testing from our server — see site availability from outside, not just your local network.

Uptime Monitoring

Need constant monitoring? Create a monitor — checks every minute with notifications.

Who uses this

DevOps

availability diagnosis

Network engineers

TCP port scanning

Developers

connection debugging

SRE

basic health check

Common Mistakes

ICMP blocked = server is downMany servers block ICMP. Ping fails but site works — check ports instead.
High ping = server problemLatency depends on geography. 150ms between continents is normal, not an error.
Closed ports — cause for alarmClosed ports of unused services are good. Unnecessary open ports are a risk.
One check = sufficientNetworks are unstable. A single timeout ≠ a problem. Check multiple times or set up monitoring.

Best Practices

Combine ping and port checksPing shows host availability, ports show specific service availability. Use both.
Check from different locationsThe problem may be local. A cloud test shows the real picture.
Close unused portsEvery open port is a potential attack vector. Keep only necessary ports open.
Set up monitoringManual checks do not scale. Set up automated monitoring with notifications.

Get more with a free account

Ping check history, host availability monitoring and downtime alerts.

Sign up free

Learn more

Sources

Frequently Asked Questions

What is the difference between ECONNRESET and socket hang up?

Both carry the code ECONNRESET. socket hang up is the message the Node.js http client uses when the connection closes before a response arrives.

Why does ECONNRESET happen only sometimes?

Usually a keep-alive race: the client reuses an idle socket at the moment the server closes it. Make the server's keep-alive timeout longer than the client's.

Should I retry on ECONNRESET?

Retry once for idempotent requests such as GET, ideally only when the socket was reused. Do not blindly retry non-idempotent POSTs.

Is ECONNRESET a client or a server problem?

It is reported by the side that received the reset. The cause is on the other side or in between: a closed keep-alive socket, a crash, a proxy timeout or a firewall.

What does ECONNRESET errno -104 mean?

104 is the Linux number for ECONNRESET; Node.js reports system errors as negative errno values.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.