ECONNREFUSED
Linux / POSIXERRORCommonNetworkHIGH confidence

Connection Refused

What this means

The remote host actively refused the TCP connection. No process is listening on the specified port, or a firewall rule is sending TCP RST packets to reject incoming connections. Unlike a timeout, connection refused is immediate.

Why it happens
  1. 1No service is listening on the target host and port.
  2. 2The service crashed and is no longer accepting connections.
  3. 3A firewall rule using REJECT (not DROP) is blocking the connection.
  4. 4The port number is wrong — the service is listening on a different port.
How to reproduce

Connecting to a port with no server listening.

trigger — this will error
trigger — this will error
$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Connection refused

expected output

curl: (7) Failed to connect to localhost port 8080 after 0 ms: Connection refused

Fix

Verify the service is running and listening

WHEN When you expect a service to be available

Verify the service is running and listening
# Check if anything is listening on the port
sudo ss -tlnp | grep :8080

# Check service status
systemctl status myapp.service

# Start the service if stopped
systemctl start myapp.service

Why this works

ss shows all listening TCP sockets. If nothing appears for the port, no service is bound there.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors