For a TCP client connect() call to a TCP server..
UNIX® Network Programming book by Richard Stevens says the following..
If the client TCP receives no response to its SYN segment, ETIMEDOUT is returned. 4.4BSD,
for example, sends one SYN when connect is called, another 6 seconds later, and another
24 seconds later (p. 828 of TCPv2). If no response is received after a total of 75 seconds, the
error is returned.
In Linux I would like know what is the retry mechanism (how many times and how far apart). Asking because for a TCP client connect() call I am getting ETIMEDOUT error. This socket has O_NONBLOCK option and monitored by epoll() for the events.
If someone can point to me where in the code this retry logic is implemented that would be helpful too. I tried following a bit starting with tcp_v4_connect() from net/ipv4/tcp_ipv4.c, but lost my way pretty soon..
The timeout is scaled based on the measured round-trip time.
tcp_connect()sets up a timer:The
icsk_rtowill use a per-destination re-transmission timeout; if previous metrics from the destination is available from previous connections, it is re-used. (See thetcp_no_metrics_savediscussion intcp(7)for details.) If no metrics are saved, then the kernel will fall back to a default RTO value:tcp_retransmit_timer()has some code near the bottom for recalculating the delay:retransmits_timed_out()will first perform a linear backoff then an exponential backoff.I think the long and the short of it is that you can reasonably expect roughly 120 seconds before getting
ETIMEDOUTerror returns fromconnect(2)unless the kernel has good reason to suspect that the remote peer should have replied sooner.