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 →
ECONNREFUSEDECONNRESET
WhenAt connect — actively rejectedAfter connecting — closed abruptly
SpeedInstantMid-request
Usual causeService down / wrong port / wrong host in DockerStale 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.