Skip to content

Commit 97a9063

Browse files
edumazetkuba-moo
authored andcommitted
tcp: avoid too many retransmit packets
If a TCP socket is using TCP_USER_TIMEOUT, and the other peer retracted its window to zero, tcp_retransmit_timer() can retransmit a packet every two jiffies (2 ms for HZ=1000), for about 4 minutes after TCP_USER_TIMEOUT has 'expired'. The fix is to make sure tcp_rtx_probe0_timed_out() takes icsk->icsk_user_timeout into account. Before blamed commit, the socket would not timeout after icsk->icsk_user_timeout, but would use standard exponential backoff for the retransmits. Also worth noting that before commit e89688e ("net: tcp: fix unexcepted socket die when snd_wnd is 0"), the issue would last 2 minutes instead of 4. Fixes: b701a99 ("tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy") Signed-off-by: Eric Dumazet <[email protected]> Cc: Neal Cardwell <[email protected]> Reviewed-by: Jason Xing <[email protected]> Reviewed-by: Jon Maxwell <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e1533b6 commit 97a9063

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

net/ipv4/tcp_timer.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,26 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
483483
const struct sk_buff *skb,
484484
u32 rtx_delta)
485485
{
486+
const struct inet_connection_sock *icsk = inet_csk(sk);
487+
u32 user_timeout = READ_ONCE(icsk->icsk_user_timeout);
486488
const struct tcp_sock *tp = tcp_sk(sk);
487-
const int timeout = TCP_RTO_MAX * 2;
489+
int timeout = TCP_RTO_MAX * 2;
488490
s32 rcv_delta;
489491

492+
if (user_timeout) {
493+
/* If user application specified a TCP_USER_TIMEOUT,
494+
* it does not want win 0 packets to 'reset the timer'
495+
* while retransmits are not making progress.
496+
*/
497+
if (rtx_delta > user_timeout)
498+
return true;
499+
timeout = min_t(u32, timeout, msecs_to_jiffies(user_timeout));
500+
}
490501
/* Note: timer interrupt might have been delayed by at least one jiffy,
491502
* and tp->rcv_tstamp might very well have been written recently.
492503
* rcv_delta can thus be negative.
493504
*/
494-
rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp;
505+
rcv_delta = icsk->icsk_timeout - tp->rcv_tstamp;
495506
if (rcv_delta <= timeout)
496507
return false;
497508

0 commit comments

Comments
 (0)