Data retransmission and WSAECONNABORTED (10053) socket error
Say I have two sockets that are connected to each other (Socket A
and Socket B
).
If the computer that have Socket B
is unplugged from power, then if Socket A
tries to send some data to Socket B
, the data will not get acknowledged and so TCP will retransmit the data again and again in hope for an acknowledgment, until TCP gives up and decides not to retransmit the data anymore and tells Socket A
that the socket error WSAECONNABORTED (10053)
has occurred.
My questions are:
- Is it guaranteed that I will always get the socket error
WSAECONNABORTED (10053)
after some retransmission retries (I believe it is, because otherwise TCP will just continue to retransmit forever!)? - How many retransmission retries does it take for TCP to decides to give up and causes the
WSAECONNABORTED (10053)
socket error? - Is this number of retransmission retries configurable?
Windows timers for TCP use a unit of time called retransmission timeout (RTO) that is based on the estimated round-trip time (or RTT) between the sender and receiver, as well as the variance in this round trip time. The behavior of this timer is specified in RFC 6298. For more information see the Wikipedia article Transmission Control Protocol.
The way it works in Windows is as follows :
- An estimated RTO is first established
- The TCP message is sent and we wait for an ACK (acknowledge) packet
- If the ACK has not arrived, we double the wait time and go back to step 2
- If the ACK is received, a new RTO is calculated
- IF an ACK is never received, the connection is aborted with error WSAECONNABORTED.
Windows uses two registry parameters for this protocol, described in this Microsoft article
How to modify the TCP/IP maximum retransmission time-out.
TcpMaxDataRetransmissions
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters
Value Name: TcpMaxDataRetransmissions
Data Type: REG_DWORD - Number
Valid Range: 0 - 0xFFFFFFFF
Default: 5
Description :
This parameter controls the number of times TCP retransmits an individual data segment (non connect segment) before aborting the connection. The retransmission time-out is doubled with each successive retransmission on a connection. It is reset when responses resume. The base time-out value is dynamically determined by the measured round-trip time on the connection.
TCPInitialRtt
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\ID for Adapter
Value Name: TCPInitialRtt
Data Type: REG_DWORD
Valid Range: 300-65535 (milliseconds in decimal)
Default: 0xBB8 (3000 milliseconds expressed in hexadecimal)
Description:
This parameter controls the initial retransmission time-out that is used by TCP on each new connection. It applies to the connection request (SYN) and to the first data segments that is sent on each connection. For example, the value data of "5000 decimal" sets the initial retransmit time to five seconds.
NOTE: You can increase the value only for the initial time-out. Decreasing the value is not supported.
Although TCPInitialRtt starts with an initial timeout of 3 seconds, it will be smoothed-out to a more reasonable value when packets are transmitted correctly.
For example of how this works, if we take the default values of 3 seconds RTO and 5 retries, the total wait-time will be :
- first timeout time : 3 seconds
- second timeout : 6 seconds
- third timeout : 12 seconds
- fourth timeout : 24 seconds
- fifth and last timeout : 48 seconds
Which gives a total wait-time of 93 seconds before the connection is aborted. In most cases, if the connection has ever worked correctly, the timeout will be much less.