Bobcares

Fix cURL 56 recv failure: Connection Reset by Peer in CentOS

PDF Header PDF Footer

Having trouble with cURL 56 recv failure connection reset by peer in the CentOS server?

The error occurs mainly due to failure in receiving network data.

At Bobcares, we often get requests to fix cURL errors as part of our Server Management Services.

Today, let’s get into the details on how our Support Engineers fix this error.

Why does cURL 56 recv failure connection reset by peer occurs?

cURL error 56 is a temporary error that happens due to different reasons like, idle server connection, firewall restrictions, whitespace in the URL, etc.

In fact, this error message indicates that a connection to a remote server was unexpectedly closed by the peer while cURL was trying to receive data.

Maybe the server abruptly closed the connection before cURL could receive any data, causing the “recv failure.”

The error “Connection reset by peer” occurs when the server closes the connection while there is still unread data from the client. In this case, a TCP RST (reset) packet is sent. That’s exactly what’s happening here: curl sends an HTTP request, but the server doesn’t read it and instead immediately terminates the connection.

This issue can also occur on CentOS and other OSs for different reasons. Here are some common causes and troubleshooting steps:

  • The remote server may experience issues like high load, crashing, and improper configuration. This resets the connection.
  • Firewall rules or security policies on the server may be terminating the connection.
  • Network interruptions or unstable network connections between the CentOS machine and the remote server can cause this error.
  • Misconfigured network equipment along the path can also result in connection resets.
  • Firewall rules or security settings on the CentOS machine may interfere with the connection.
  • Incorrect cURL options or usage may cause the problem.

For instance, a related issue like cURL 52: empty reply from server might point to a similar server-side termination.

For instance, the error appears as follows.

cURL 56 recv failure connection reset by peer CentOS

Let’s detail how our Support Engineers fix this for our customers.

How do we fix this error cURL error?

At Bobcares, we have more than a decade of expertise in managing servers, we see many customers facing errors. It happens mainly when fetching package updates, installing new software, etc.

Now, let’s see the major reasons and how our Support Engineers fix this error.

Solution 1. Idle server connection

Recently, one of the customers approached us with a cURL error. He was getting the following error while transferring the backup to the remote destination.

cURL error 56: TCP connection reset by peerCopy Code

So we checked the backup log files and confirmed that the backups have been generated successfully.

On further checking, we found that the server was idle while transferring the backups to the remote destination. However, the backups were successfully exported to Google drive.

In addition, to avoid this situation, the tips we follow are:

  • We always upgrade the user’s OS to avoid TCP/IP issues.
  • Also, we use the recent versions of PHP and cURL.
  • Set the Maximum Transmission Unit (MTU) or the size of packets traveling over the network to the default value, 1500 bytes.
  • We ensure that the firewall is not blocking the user’s connection.

Solution 2. Bad repository

Often bad repository URLs can also trigger curl 56 errors.

For instance, while trying to install PHP on the CentOS7 server one of our customers received the error:

Loaded plugins: fastestmirror, langpacks
http://mirror.xxx.net/el7-x86_64/rpms/ ... repomd.xml: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.Copy Code

Here, the customer was using an outdated repository and that caused the error. Therefore, we corrected the repo settings on the server and the package install went on fine.

Similarly, the repository may fail to load due to DNS resolution failures as well. In such scenarios, we make use of the /etc/hosts files to map the repo website to the correct IP address.

Sometimes, repo errors may relate to deeper issues like NSS library initialization failures.

Solution 3. Whitespace in the URL

Another customer approached us with a similar problem.

On further investigation, we found whitespace in the URL. We then removed whitespace from the URL.

And in the PHP settings, we added the following.

curl_setopt($ch, CURLOPT_URL, trim($url));Copy Code

In addition, If whitespace is a valid part of the URL, we use rawurlencode() function in PHP, to store the URL as encoded including whitespace.

Solution 4: Whitelist Required Domains

In some cases, cURL errors occur because required domains are blocked by the server or hosting provider.

Hence, we need to contact the hosting provider and request that the following domains be whitelisted:

  • wpml.org
  • cdn.wpml.org
  • api.wpml.org

Additionally, ensure that the PHP cURL extension is configured correctly and up to date on the server, particularly important when troubleshooting SSL-related errors, such as cURL 60: SSL certificate problem. If there’s any doubt, ask the hosting provider to update the cURL extension and confirm that SSLv3 is allowed.

Solution 5: Disable the Firewall

In some cases, the server’s firewall may be blocking outgoing cURL requests.

Then, disable the firewall temporarily to test if it was the cause with these commands:

systemctl disable firewalld
systemctl stop firewalldCopy Code

After disabling the firewall, the cURL requests will begin functioning correctly.

Solution 6: Reset the Docker Network Interface

Sometimes resetting the Docker network interface can resolve the problem.

# Stop the Docker service
systemctl stop docker
# Bring down the docker0 interface
ip link set dev docker0 down
# Delete the docker0 bridge
brctl delbr docker0
# Recreate the docker0 bridge
brctl addbr docker0
# Assign IP to docker0 interface
ip addr add 172.16.10.1/24 dev docker0
# Bring the interface up
ip link set dev docker0 up
# Restart the Docker service
systemctl restart docker
Copy Code

Finally, verify connectivity by opening Firefox and accessing localhost:3344.

Additional Tips

  1. Make sure the remote server is up and running properly.
  2. Look for any known issues or maintenance notifications from the service provider.
  3. Check the network connection and try to access other resources to confirm there are no general connectivity issues.
  4. Use tools like ping or traceroute to diagnose network problems.
  5. Try increasing the timeout settings using –connect-timeout and –max-time.
  6. Use the -v option with cURL to get more detailed output, which can help in diagnosing the problem.
  7. Make sure to use the correct URL and HTTP method.
  8. Verify that the local firewall settings are not blocking the connection.
  9. Check if there are any security appliances (like an IDS/IPS) that might be resetting the connection.
  10. Examine the URL used in the cURL command. Ensure it’s correct and includes the protocol (http:// or https://).
  11. On the CentOS machine, use tools like firewall-cmd –list-all to see if any firewall rules are blocking outgoing connections on the relevant port (usually 80 or 443).
  12. If possible, try running the same cURL command from a different network to rule out issues with your local network.

If you’re facing SSL certificate issues, it might be worth reviewing known problems like cURL error 77.

FAQs

Q. What is cURL error 56 (SMTP)?

It typically occurs when data is passed in the URL instead of a POST request, a proxy blocks the request, or the server doesn’t support the request method (e.g., only POST or PUT).

Q. What does “Connection reset by peer” mean?

The server closed the connection unexpectedly, often due to network issues, firewalls, or server-side restrictions.

Q. How to fix cURL 56 recv failure?

Increase timeout settings (–connect-timeout, –max-time), use -v for details, verify the URL and method, and check local firewall rules.

Q. What is cURL 56 with HTTP code 502?

It means Bad Gateway. Check proxy settings or remove them to connect directly.

[Need assistance in fixing cURL errors? – We can help you.]

Conclusion

In short, cURL 56 recv failure connection reset by a peer in CentOS occurs when the server is idle due to running a long process or due to improper usage of URL. Today, we saw how our Support Engineers fixed the error.

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

7 Comments
  1. Hiba Razak

    Hi,
    Glad to know that our article helps you solves the issue ? .

    Reply
  2. Vaibhav Wasnik

    Im still stuck in this error i have pull the image of jenkins application by creating dockerfile and when i went to
    run jenkins application on port so got this error

    curl localhost:9090

    connection reset by peer how could i solve this issue

    could anaybody guide me

    Reply
    • Hiba Razak

      Hi Vaibhav,
      Our experts can help you with the issue.we will be happy to talk to you through our live chat(click on the icon at right-bottom).

      Reply
  3. Suchita

    While connecting to the valid url from rhel8 vm getting below error how we can resolve this issue
    * Recv failure: Connection reset by peer
    * Closing connection 0
    curl: (56) Recv failure: Connection reset by peer

    Reply
    • Hiba Razak

      Hi Suchita,
      Our experts can help you with the issue.we will be happy to talk to you through our live chat(click on the icon at right-bottom).

      Reply
  4. Ferhat

    Hi, While I am downloading a file using curl command in Windows terminal, I close internet connection but curl gives me “curl: (56) Recv failure: Connection was reset” error. I expect curl is waiting for internet reconnection. In other hand, when I try it on Linux terminal, I don’t get error but download process doesn’t continue after internet reconnection. How can I resolve this?

    Reply
    • Hiba Razak

      Hello,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!