How To Fix the Error “Connection Reset by Peer”

Did you get error messages such as “Connection reset by peer” or “Socket write error?” You may be curious about what causes them and what they mean.

This article explains these error messages and why we receive them.

What does it mean?

A “connection reset by peer” error means that the TCP stream has been shut down from the other end of the connection for some reason. In other words, the TCP RST has been sent and received, but the connection is closed.

This issue can occur when you send a packet on your end of the connection, but the other end doesn’t recognize the connection. It returns a packet with an RST bit to close the connection.

The error can occur when the peer crashes. Other times, it is due to poorly written applications not closing their TCP connections properly.

One possible solution to this is to edit the hosts.deny file. For those using nano on a Debian based system, type or paste this line.

sudo nano /etc/hosts.deny

Look for your local IP address or hostname in the file.

  1. Log in to your remote server.
  2. After accessing the file and clearing the IP or hostnames, save and exit.
  3. Try connecting via SSH again.
  4. Type this line as a precaution:

sudo nano /etc/hosts.allow

  • Open this file and add your hostname and IP address.
  • Save the file and close it.
  • Try to establish an SSH connection again.

It is essential to remember that once you enable these settings, you will limit your ability to maintain or manage remote servers. Do not proceed until you understand the risks.

Change Fail2ban

Fail2ban protects users from brute-force attacks, and if you try to connect multiple times, the software can be fooled into thinking you are an attacker. As a result, you need to configure the file and add the IP or IP ranges to the whitelist.

  1. Access your remote server.
  2. Enter “sudo nano /etc/fail2ban/jail.conf”.
  3. Once you’re in the file, add the IP address or range to the “ignoreip =+” line.
  4. Save and close.

From then on, Fail2ban will let you through.

Check sshd_config

If the error persists, the problem may be in the sshd_config. Try these steps to resolve the issue.

  1. Enter “tail -f /var/log/auth.log” to read the latest log entries.
  2. Once you find clues, type and enter “sudo nano /etc/ssh/sshd_config”.
  3. Edit the file so that your system can accept more connections.
  4. Save the file.
  5. Restart the sshd service.

Do not attempt to edit it unless you are familiar with the variable. This may result in an unreachable server. If none of these solutions work, please contact your host for assistance.

Reset connection by peer with socket write error

Sometimes you may have trouble connecting to a remote computer and get the message ‘Connection reset due to peer socket write error’. There are several possible causes, such as connections terminated abruptly, the socket receiving a command to close, and more.

The first task is to find out if your server is reachable.

  1. Open the command prompt.
  2. Type “ping” along with the server’s address. Run the command.
  3. Run “tracert” and the server address to see if the request is successful.
  4. Run “telnet” and enter the server address to see if the local machine ports are open.
  5. If the connection fails, run SDEINTERCEPT and diagnose the problem.

Occasionally this error comes with “SocketException”. It occurs when data is written or read to or from a closed socket connection. Below are some possible root causes.

  • Firewalls closing socket connections
  • A slow network connection
  • Long idle connection
  • Application errors

A slow connection can be solved by setting a longer socket timeout period. This prevents any sockets from closing before connections are possible.

As for firewalls, you can disable or configure them to avoid a SocketException.

The best solution for inactive connections is to send heartbeat messages. These are periodic and prevent the server from becoming idle, which will stop the server and save resources.

One of the best solutions for a SocketException is to surround or throw it with a try-catch block. Close the connection to the server and start a new one. You can fix the error this way.

Oddly enough, Adobe claims that you can ignore the error.

Reset connection by peer with a cURL command

A cURL error 56 is sometimes encountered by clients when trying to connect to the server. It is usually because the server is not receiving incoming network information. The following are more precise causes:

  • Inactive server connections
  • URL space
  • Restrictions in the firewall

A server upgrade, cURL update, and firewall configuration usually resolves the server idle issue. It is also helpful to set the maximum transmission unit to 1500 bytes, which is the default value.

A problematic URL is enough to trigger cURL 56 errors as well. Simply updating the repository should restore the functionality of the server.

Whitespace is also easy to remove. The command to do that removes the whitespace indiscriminately. However, if the URL contains white space intentionally, it should be left alone.

If none of these solutions help, contact your host for assistance.

Additional FAQs

What is a SocketException?

A SocketException is when a socket error occurs. Both Socket and DNS classes give this error when the network is not configured correctly.

Why are sockets closed?

If your server sockets are closed, it could be due to a disconnection, but there is no specific reason given. The driver is not aware or sure of what happened to the connection.

What is a cURL error?

There are many cURL errors, but they are often the result of outdated PHP or cURL versions. They have nothing to do with SSLs, but are a server issue. Usually you will not notice anything at the front of your website.

Back to normal

Connection reset due to peer errors comes in different forms and it is impossible to cover them all in one article. However, some of the above solutions tend to address common issues. If all else fails, it’s best to consult a professional or host.

Which of these errors have you encountered? Do you know other solutions? Let us know in the comments below.

Be the first to comment

Leave a Reply

Your email address will not be published.