ECONNREFUSED vs ECONNRESET vs ETIMEDOUT
Three network failures at different moments: refused (nothing listening), reset (connection closed abruptly mid-use), timed out (no answer at all).
ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:5432
Nothing is listening at that host:port — the target service is down or you’re connecting to the wrong address.
Causes & fixes →
ECONNRESET
Error: socket hang up / read ECONNRESET
The other side closed the TCP connection abruptly while your client was still using it.
Causes & fixes →| ECONNREFUSED | ECONNRESET | |
|---|---|---|
| When | At connect — actively rejected | After connecting — closed abruptly |
| Speed | Instant | Mid-request |
| Usual cause | Service down / wrong port / wrong host in Docker | Stale keep-alive, server crash, proxy idle timeout |
| ETIMEDOUT instead? | Packets dropped by a firewall → no answer at all | — |
Rule of thumb
Refused → is it running on that host:port? Reset → who closed it and why? Timed out → firewall/routing or a very slow server.