Re: [PATCH net-next v3 3/3] net: tcp: fix unexcepted socket die when snd_wnd is 0

From: Menglong Dong
Date: Tue Aug 08 2023 - 12:33:25 EST




> On Aug 8, 2023, at 20:49, Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
>
> On Tue, Aug 8, 2023 at 1:59 PM <menglong8.dong@xxxxxxxxx> wrote:
>>
[……]
>>
>> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
>> index d45c96c7f5a4..f30d1467771c 100644
>> --- a/net/ipv4/tcp_timer.c
>> +++ b/net/ipv4/tcp_timer.c
>> @@ -454,6 +454,18 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
>> req->timeout << req->num_timeout, TCP_RTO_MAX);
>> }
>>
>> +static bool tcp_rtx_probe0_timed_out(struct sock *sk)
>
> const struct sock *sk
>
>> +{
>> + struct tcp_sock *tp = tcp_sk(sk);
>
> const struct tcp_sock *tp = tcp_sk(sk);
>
>> + u32 timeout_ts, rtx_ts, rcv_ts;
>> +
>> + rtx_ts = tp->retrans_stamp;
>> + rcv_ts = tp->rcv_tstamp;
>> + timeout_ts = after(rtx_ts, rcv_ts) ? rtx_ts : rcv_ts;
>> + timeout_ts += TCP_RTO_MAX;
>
> If we are concerned with a socket dying too soon, I would suggest
> adding 2*TCP_RTO_MAX instead of TCP_RTO_MAX
>
> When a receiver is OOMing, it is possible the ACK RWIN 0 can not be sent all,
> so tp->rcv_tstamp will not be refreshed. Or ACK could be lost in the
> network path.

Yeah, I concern abort this too. I introduce the funtion “tcp_rtx_probe0_timed_out()”
here is to offer a more reliable way to check the timeout in the feature.
And for this time, we can fix the problem first, as you advised, adding
2*TCP_RTO_MAX instead of TCP_RTO_MAX.

> This also suggests the net_dbg_ratelimited("Peer %pI4:%u/%u
> unexpectedly shrunk window %u:%u (repaired)\n"...) messages
> are slightly wrong, because they could be printed even if we did not
> receive a new ACK packet from the remote peer.
>
> Perhaps we should change them to include delays (how long @skb stayed
> in rtx queue, how old is the last ACK we received)

Sounds great, which is more valuable. I’ll change them
in the next version.

Thanks!
Menglong Dong

>> +
>> + return after(inet_csk(sk)->icsk_timeout, timeout_ts);
>> +}
>>
>> /**
>> * tcp_retransmit_timer() - The TCP retransmit timeout handler
>> @@ -519,7 +531,7 @@ void tcp_retransmit_timer(struct sock *sk)
>> tp->snd_una, tp->snd_nxt);
>> }
>> #endif
>> - if (tcp_jiffies32 - tp->rcv_tstamp > TCP_RTO_MAX) {
>> + if (tcp_rtx_probe0_timed_out(sk)) {
>> tcp_write_err(sk);
>> goto out;
>> }
>> --
>> 2.40.1