As easy as programming has become in recent years, random bugs and glitches are still the order of the day when writing code. This also applies across platforms and libraries. In most cases, just because you see an error somewhere doesn’t mean you can’t see it with a different language and platform combination.
In this article, we’re talking about the “an existing connection was forcibly closed by the remote host” error, its causes and what you can do to fix the problem.
What causes this error?
As the error suggests, it’s triggered when the remote side terminates the connection, usually by sending a TCP/IP RST packet. If you have a third-party application in the mix, that increases the chances of failure. Common causes include:
- The network link between the client and the server isn’t working properly.
- A third-party application doesn’t have system resources.
- Input data sent to the application isn’t formatted correctly.
- Third-party application bug.
Also read: How to fix Ray out of memory error in Python?
How to fix this?
Here are five fixes you can try out.
Check server validity
The first thing you should do to check to see if the remote server that you’re trying to connect to is working in the first place. Server applications, especially ones that run remotely without active supervision, can sometimes crash and stay that way unless someone manually reboots them.
Restart your router
Power cycling your network equipment is the fix to more issues than you think. More often than not, connectivity issues can be caused by an underlying bug in your router and can be fixed by rebooting.
Use TLS 1.2
Several users have reported that forcing your application to use TLS version 1.2 can resolve the error. The program shouldn’t give this error as long as you’re implementing and executing TLS before calling your service.
Ensure active SSL certificates
Similar to using TLS 1.2, check to make sure you’ve got an active SSL certificate bound to the port you’re using to connect to the remote server.
Update the .NET version
Based on what .NET framework version you’re using, there’s a good chance you might run into this error. Updating the .NET framework version to 4.6 or higher, paired with using a proxy, can resolve the error for you.
Also read: How to fix Compilation error: Script could not be translated from: Null?