How to fix WSAECONNABORTED error?
You are correct.
The former results from network problems. All you can do is try again with a new socket.
The latter is an application protocol error. You're sending while the peer has already closed. This is an application bug. The cure is to fix the bug.
fumin
Updated on June 05, 2022Comments
-
fumin almost 2 years
I have a C/S application. The client usually send a large amount of data to server using TCP protocol. It works well in LAN environment(10MB/s), but network errors happen when I migrate it to WAN environment(200KB/s).
As I track the bug, I find that
send()
in client returns -1 andWSAGetLastError()
returnsWSAECONNABORTED
at first; And several seconds later,recv()
in server also returns -1 anderrno
isECONNRESET
.After consulting documents, I have a basic understanding of
WSAECONNABORTED
andECONNRESET
. I think the former is resulted from the bad network: TCP closes the socket after several retransmission failures. And the latter is resulted from the unexpected close operation in client.I wonder how to handle this kind of error. Reconnect immediately? Or any socket options can help?
-
curzonnassau over 11 yearsLike most error codes WSAECONNABORTED has many causes. The most common I find is when I'm trying to use a socket that was modified elsewhere by shutdown() or closesocket(). I would check the timing of how you handle the FD_CLOSE event. It is perfectly possible to receive an FD_CLOSE so soon after an FD_READ, that the read function failed to finished before the socket was closed. Invariably the problem is going to be the way your software handles network events - or more precisely the order in which it handles those events. Hope this helps. :o)
-
user207421 almost 4 years@curzonnassau Neither shutdown nor close elsewhere in the application can possibly cause this problem, and the read function cannot possibly fail before the socket is closed, by the nature of TCP.
-
-
MD XF about 7 years"The cure is to fix the bug" +1