ECONNRESET and ECONNREFUSED: Connection Reset or Refused

These are system connection errors shown by Node.js and many other programs. One means the connection was dropped, the other that it was not accepted.

Updated · Prokso editorial team

Key takeaways
  • ECONNREFUSED means the connection was not accepted, and ECONNRESET means it was dropped
  • ECONNREFUSED almost always concerns the connection to the proxy: a wrong host or port
  • Copy the proxy line from the dashboard again and check the host gw.prokso.com and the port

What the error means

According to the Node.js documentation, ECONNREFUSED (Connection refused) means no connection could be made because the target machine actively refused it. This usually happens when no service is running on that port on the remote host.

ECONNRESET (Connection reset by peer) means the other side forcibly closed the connection. The documentation explains this as a loss of the connection on the remote side due to a timeout or reboot; the error is most often encountered in the http and net modules.

Through a proxy, your program connects to the proxy, not to the site. So ECONNREFUSED almost always concerns the connection to the proxy itself: if the site refuses, the proxy reports it with its own response, for example a 502 code.

Causes

  • The wrong proxy host or port. For ECONNREFUSED: a port other than 823, 824 and 10000-20000, or an error in the host name.
  • The program does not use the proxy. The proxy settings were not applied, and the program goes to a different host where nothing listens on the port.
  • The connection to the exit device dropped. For ECONNRESET: a residential or mobile address left the network, and the sticky IP port got a new IP.
  • The site closed the connection. The site drops connections at its own discretion, for example for requests over the limit.
  • Reusing a closed connection. The program sends a request over a keep-alive connection that the other side has already closed.

How to fix it

  1. For ECONNREFUSED, copy the proxy line from the dashboard again and check the host gw.prokso.com and the port.
  2. Make sure the program really goes through the proxy: log the address it connects to. A setup example is in the Node.js guide.
  3. For ECONNRESET, add a request retry with a pause to the program: on rotation ports, the retry will go through a new IP.
  4. Reduce the number of parallel threads and the request rate to a single site.
  5. If ECONNRESET comes on long tasks with a sticky IP, keep in mind that the session duration is limited: from 1 to 120 minutes depending on the port settings.

How to check that it works

Paste the line into the proxy checker. If the connection goes through, the host and port are correct, and the cause should be looked for in the program settings or in the site's behavior.

Two-minute diagnosis

First paste the line into the proxy checker. If the proxy works there, the cause is in your app or its settings. If not, test the line from a terminal:

curl -v -x "http://USERNAME:PASSWORD@gw.prokso.com:823" https://api.ipify.org
  • A < HTTP/1.1 407 line right after CONNECT means the proxy answered. The name after the code, for example NO_USER, points to the cause.
  • The proxy answered CONNECT with 200 and then another code arrived - the proxy works, and that answer came from the website.
  • No answer at all, only a timeout - the connection never reached the proxy: check the host, port and network.

Setup guides where this error comes up

FAQ

What should I do if ECONNREFUSED appears right at startup?

Most likely the program connects to the wrong place: a wrong port, host, or the proxy was not applied. Check the line and the program settings, and then the <a href="/en/errors/err-proxy-connection-failed">proxy connection error</a> page.

Is the proxy to blame for ECONNRESET?

Not necessarily. The connection can be reset by the site, the exit device or your network. If the error happens on all sites, write to support with the time and the plan name.

How is ECONNRESET different from ETIMEDOUT?

ECONNRESET means the connection was explicitly dropped. ETIMEDOUT means the other side did not respond in time. About timeouts, see the <a href="/en/errors/proxy-timeout">proxy timeout</a> page.

Residential $1.59, mobile $2.50, datacenter $0.65 per GB

Sign up in a minute, get access right after payment.

Create account