This tag is for you when you get ECONNREFUSED errors trying to connect to a server with http, https, tcp, or any other tcp-based protocol this. Please show the URL or hostname, and always include the port number in your question. If you're trying to connect to a service (redis, postgreSQL ...) show the service.
What is this?
ECONNREFUSED is an error from your operating system's TCP communication software. HTTP, HTTPS, WS, WSS, email, databases, and many other communications protocols use TCP.
It usually comes back promptly. Another similar error, etimedout, comes back after 30-60 seconds.
It means that your request to connect reached the host machine but found no server software running on the port you requested. When no server software is running, the host machine sends back ECONNREFUSED.
For example:
Your program please connect to MySQL on dbms.example.com port 3306.
Your OS hey, dbms.example.com, I want a TCP connection to your port 3306.
Host OS hmm, nothing here is running on port 3306. I must reply with an ECONNREFUSED message.
Your OS hey, program, I just got ECONNREFUSED. No connection for you!
Your program gets back the error and handles it however your programming environment handles errors.
You time to hit https://stackoverflow.com/questions/tagged/econnrefused
What's in the documentation?
The documentation for UNIX-heritage operating systems (MacOS, Linux, FreeBSD) says this about it.
ECONNREFUSED A connect() on a stream socket found no one listening on the remote address.
The Windows documentation says this:
WSAECONNREFUSED 10061 Connection refused No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
What to do?
If you're trying to connect to a service like MySQL, postgreSQL, redis, a webservice, or similar services, it means the service you want is not running on the machine you mentioned at the port you mentioned. If you didn't mention a port, it means the service is not running on its default port. Fix: run the service on the machine, or connect to the machine that actually has the service.
If you are trying to use a service you developed yourself, it means you forgot to run the service before you tried to connect to it. Fix: run your service.
Specific troubleshooting steps
- You already know you can reach the host machine you're connecting to, because ECONNREFUSED occurs when it actively refuses your request to connect. If the host machine is switched off or behind a firewall, you get ETIMEDOUT instead.
- You already know it's not a username / password problem; those don't generate ECONNREFUSED errors.
- If you're connecting to a server software package (a database for example), try using that service's client program to connect from your own machine. If the client program connects, then there's something wrong with the connection data in your program:
- Make sure you use the correct hostname or IP address.
- Make sure you have the correct port number.
- Make sure the server software you want to use is running on the host and port.
This error can come up when you first deploy a new project on a server after getting it to work on your own machine 127.0.0.1
, localhost
, or ::1
.