65

These errors are getting more and more frequent on my Game Server. They are causing the server to keep closing and restarting...

System.Net.Sockets.SocketException (0x80004005): An established connection was aborted by the software in your host machine 
   at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) 
   at iRP.Game.Sessions.Session.SendData(Byte[] Data)

This is the code from which these errors are generated:

public void SendData(byte[] Data)
{
    try
    {
        if (mSocket == null)
        {
            //Output.WriteLine("[SND] Socket has a null exception, which means it is now invalid. Remove this socket!", OutputLevel.CriticalError);
        }
        else
        {
            mSocket.BeginSend(Data, 0, Data.Length, SocketFlags.None, sendCallback, mSocket);
        }
    }
    catch (Exception e)
    {
        string WhatToWrite = "Error handled (SESSION): " + e.ToString() + "\n\n" + e.Message + "\n\nStack: " + e.StackTrace + Environment.NewLine + "\n\n";
        File.AppendAllText(Environment.CurrentDirectory + "\\data\\fatal.txt", WhatToWrite);
        Program.Stop();
    }
}

The buffer sizes are correctly set, we are using KeepAlive on the socket and were using Send and Receive Timeouts.

People suggested that disabling the firewall would help, but whenever I do this our Game Server (Dedicated Server) restarts itself as if it's under attack, so the firewall must remain enabled.

Anyone else got any other solutions for this?

PS: We are behind DDoS Mitigation Services which may be limiting the number of connections...

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
Richard Williams
  • 683
  • 1
  • 5
  • 4
  • What exactly are these DDoS Mitigation Services ? You can run the netstat command at the server and see the number of established connections and see if is exceeding the limit set up by your DDoS mitigation services – prthrokz Jan 13 '13 at 15:20
  • I get unlimited connections, but maybe when it is saying software on your host machine it means the DDoS Mitigation – Richard Williams Jan 13 '13 at 15:57

5 Answers5

87

An established connection was aborted by the software in your host machine

That is a boiler-plate error message, it comes out of Windows. The underlying error code is WSAECONNABORTED. Which really doesn't mean more than "connection was aborted". You have to be a bit careful about the "your host machine" part of the phrase. In the vast majority of Windows application programs, it is indeed the host that the desktop app is connected to that aborted the connection. Usually a server somewhere else.

The roles are reversed however when you implement your own server. Now you need to read the error message as "aborted by the application at the other end of the wire". Which is of course not uncommon when you implement a server, client programs that use your server are not unlikely to abort a connection for whatever reason. It can mean that a fire-wall or a proxy terminated the connection but that's not very likely since they typically would not allow the connection to be established in the first place.

You don't really know why a connection was aborted unless you have insight what is going on at the other end of the wire. That's of course hard to come by. If your server is reachable through the Internet then don't discount the possibility that you are being probed by a port scanner. Or your customers, looking for a game cheat.

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    Hi Hans, We also facing the same kind of issue while connecting to another IP via FTP. we made sure that there is no anti-virus or firewall on both the sides. The wondering thing is, the issue is not happening consistently :( – Prasanna Dec 23 '13 at 06:33
  • 4
    So if `10053 WSACONNABORTED ConnectionAborted The connection was aborted locally.` is used when the connection was in fact aborted by the remote end of the connection, when would `10054 WSAECONNRESET ConnectionReset The connection was reset by the other end.` be used? – Evgeniy Berezovsky May 07 '14 at 07:24
  • @EugeneBeresovsky This answer isn't correct. If the peer sends a reset the error code is WSAECONNRESET. – user207421 Jan 25 '15 at 03:07
  • 2
    The *question* is about aborts. Part of your *answer* concerns a situation where a rest is sent. Not an abort. – user207421 Aug 24 '15 at 12:34
  • Where would I find the underlying error code? WSAECONNABORTED? It isn't in the exception detail was provided by the OP – Dave Lawrence Aug 28 '15 at 09:56
  • 2
    That's what happens when you catch Exception instead of SocketException. It is SocketException.ErrorCode – Hans Passant Aug 28 '15 at 10:24
  • 1
    Could a connection via `Loopback Adapter` generate this exception? – Mhd Jun 29 '17 at 14:14
  • 2
    This answer is confusing. It seems WSAECONNABORTED means the local side of the connection decided to abort. In the case the remote side of the connection decides to abort in Windows you get "An existing connection was forcibly closed by the remote host". See: https://stackoverflow.com/questions/2582036/an-existing-connection-was-forcibly-closed-by-the-remote-host – Ryan Nov 30 '17 at 15:31
  • This might not be specific to windows. Heres a similar error happening on android: https://stackoverflow.com/questions/5618664/an-established-connection-was-aborted-by-the-software-in-your-host-machine – MoralCode Mar 16 '22 at 21:07
  • 2
    Here is an article that does an excellent job of explaining this error message and what causes it: https://www.chilkatsoft.com/p/p_299.asp – MoralCode Mar 30 '22 at 18:59
5

This problem appear if two software use same port for connecting to the server
try to close the port by cmd according to your operating system
then reboot your Android studio or your Eclipse or your Software.

yacine
  • 147
  • 1
  • 6
2

While the answer from Hans is an excellent high level summary of the error that worked great for getting me started, I ended up finding a page that explained the root cause well enough that I was able to recreate it with a python script.

The page presents a couple different descriptions of this error that are more detailed than the "connection was aborted" paraphrasing from Hans's answer but still pretty cryptic and not very informative.

The post then explains this scenario that would produce the error:

An HTTP POST is to be sent to an HTTP server. The server begins reading the POST and notices that the HTTP request header is invalid. It immediately sends an HTTP response (with an error status, perhaps status=400) and closes the connection without trying to continue reading the remainder of the HTTP request that is forthcoming.

Meanwhile, the client is still happily writing the remainder of the HTTP request to the socket. (Remember a TCP/IP socket connection needs to be closed from both sides. In this case, the server has closed its side, but the client is still pumping data into the half-open connection.) The client finishes writing the HTTP POST to the socket — meaning that data has been buffered to Winsock. The client application then tries to read the HTTP response, but it cannot because the outgoing retransmission (of the buffered data by WinSock) failed and the socket connection was shutdown on the client side (by Winsock). Even though the HTTP server sent the response, it is lost and cannot be retrieved. The error your application will receive when trying to read the HTTP response on the socket is WSAECONNABORTED

Wikipedia also has a page to explain what winsock is, but all you really need to know for this scenario is that its the Windows socket API.

MoralCode
  • 1,954
  • 1
  • 20
  • 42
  • 1
    Thank you, @MoralCode, for posting this. It helped me zero in on an issue producing the same "connection was aborted" error we were getting in a Go server app. – kenswdev Apr 05 '23 at 15:21
1

Could be related to the maximum number of concurrent requests. I was able to fix it with two solutions:

  • Increase the default limit of the max concurrent connections (by default it is set to 2):
ServicePointManager.DefaultConnectionLimit = 25
  • Wrap sending requests around a buffer: could use ConcurrentQueue to limit the rate, or implement a simple wait as the following:
while (activeRequests >= maxConcurrentRequests)
    Thread.Sleep(1000);

Interlocked.Increment(ref activeRequests);
var response = await _client.GetStreamAsync(endpoint);
Interlocked.Decrement(ref activeRequests);
Dr. Strangelove
  • 2,725
  • 3
  • 34
  • 61
1

I had "ManageEngine Agent" installed on my computer, which was blocking my connection to the databases, so uninstalling it was the solution.

Check which application could block the connection to your DB.

Saul
  • 26
  • 3