Each error points to a different place:
- Refused points to the service.
- A timeout points to the network path.
- A reset points to something that broke during the connection.
ECONNREFUSED: the target answered the SYN (the first packet of a TCP connection) with a reset (RST). So the host is reachable, but nothing is listening on that port. Or a firewall actively rejected the connection. This error comes fast. Check that the service is running and bound to the right address and port.
ETIMEDOUT: nothing came back at all, so the attempt timed out. This error comes slowly. Possible causes:
- A firewall or security group is silently dropping packets. This is the most common cause.
- The IP is wrong.
- The route is broken.
- The host is down.
ECONNRESET: the connection was open, but the other side or a device in the middle closed it suddenly with a reset. A device in the middle, like a load balancer, is called a middlebox. Common causes:
- The server process crashed.
- A load balancer or NAT dropped an idle connection, and your app then reused it.
- The server closed a keep-alive connection just as you sent a request.
- ECONNREFUSED means the SYN got an RST: the host is up but nothing is listening. It fails fast.
- ETIMEDOUT means no response came back, because a firewall or routing problem dropped the packets. It fails slowly.
- ECONNRESET means an open connection was stopped by a reset.
- Resets often come from crashed servers or reused idle connections.
Read more