From: "Duan,Muquan" <duanmuquan@baidu.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
"dsahern@kernel.org" <dsahern@kernel.org>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] tcp: fix connection reset due to tw hashdance race.
Date: Thu, 15 Jun 2023 12:14:03 +0000 [thread overview]
Message-ID: <FD0FE67D-378D-4DDE-BB35-6FFDE2AD3AA5@baidu.com> (raw)
In-Reply-To: <CANn89iJ5kHmksR=nGSMVjacuV0uqu5Hs0g1s343gvAM9Yf=+Bg@mail.gmail.com>
Hi, Eric,
Could you please help check whether the following method makes sense, and
any side effect? Thanks!
If do the tw hashdance in real TCP_TIME_WAIT state with substate
TCP_TIME_WAIT, instead of in substate TCP_FIN_WAIT2, the connection
refused issue will not occur. The race of the lookup process for the
new SYN segment and the tw hashdance can come to the following
results:
1) get tw sock, SYN segment will be accepted via TCP_TW_SYN.
2) fail to get tw sock and original sock, get a listener sock,
SYN segment will be accepted by listener sock.
3) get original sock, SYN segment can be discarded in further
process after the sock is destroyed, in this case the peer will
retransmit the SYN segment. This is a very rare case, seems no need to
add lock for it.
I tested this modification in my reproducing environment,
the connection reset issue did not occur and no performance impact
observed.The side effect I currently can think out is that the original
sock will live a little longer and hold some resources longer.
The new patch is a temporary version which has a sysctl
switch for comparing the 2 methods, and some modifications
for statistics of the states not included.
I checked the implementation in FreeBSD 13.1, it does the dance in
state TCP_TIMEWAIT.
Regards!
Duan
> 2023年6月8日 下午7:54,Eric Dumazet <edumazet@google.com> 写道:
>
> On Thu, Jun 8, 2023 at 1:24 PM Duan,Muquan <duanmuquan@baidu.com> wrote:
>>
>> Besides trying to find the right tw sock, another idea is that if FIN segment finds listener sock, just discard the segment, because this is obvious a bad case, and the peer will retransmit it. Or for FIN segment we only look up in the established hash table, if not found then discard it.
>>
>
> Sure, please give the RFC number and section number that discusses
> this point, and then we might consider this.
>
> Just another reminder about TW : timewait sockets are "best effort".
>
> Their allocation can fail, and /proc/sys/net/ipv4/tcp_max_tw_buckets
> can control their number to 0
>
> Applications must be able to recover gracefully if a 4-tuple is reused too fast.
>
>>
>> 2023年6月8日 下午12:13,Eric Dumazet <edumazet@google.com> 写道:
>>
>> On Thu, Jun 8, 2023 at 5:59 AM Duan,Muquan <duanmuquan@baidu.com> wrote:
>>
>>
>> Hi, Eric,
>>
>> Thanks a lot for your explanation!
>>
>> Even if we add reader lock, if set the refcnt outside spin_lock()/spin_unlock(), during the interval between spin_unlock() and refcnt_set(), other cpus will see the tw sock with refcont 0, and validation for refcnt will fail.
>>
>> A suggestion, before the tw sock is added into ehash table, it has been already used by tw timer and bhash chain, we can firstly add refcnt to 2 before adding two to ehash table,. or add the refcnt one by one for timer, bhash and ehash. This can avoid the refcont validation failure on other cpus.
>>
>> This can reduce the frequency of the connection reset issue from 20 min to 180 min for our product, We may wait quite a long time before the best solution is ready, if this obvious defect is fixed, userland applications can benefit from it.
>>
>> Looking forward to your opinions!
>>
>>
>> Again, my opinion is that we need a proper fix, not work arounds.
>>
>> I will work on this a bit later.
>>
>> In the meantime you can apply locally your patch if you feel this is
>> what you want.
>>
>>
next prev parent reply other threads:[~2023-06-15 12:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-06 6:43 Duan Muquan
2023-06-06 7:07 ` Eric Dumazet
[not found] ` <DFBEBE81-34A5-4394-9C5B-1A849A6415F1@baidu.com>
2023-06-07 13:32 ` Eric Dumazet
2023-06-07 15:18 ` Duan,Muquan
2023-06-07 15:27 ` Eric Dumazet
[not found] ` <8C32A1F5-1160-4863-9201-CF9346290115@baidu.com>
2023-06-08 4:13 ` Eric Dumazet
[not found] ` <7FD2F3ED-A3B5-40EF-A505-E7A642D73208@baidu.com>
2023-06-08 11:54 ` Eric Dumazet
2023-06-15 12:14 ` Duan,Muquan [this message]
2023-06-15 15:24 ` Eric Dumazet
2023-06-20 3:30 ` Duan,Muquan
2023-06-20 8:44 ` Eric Dumazet
2023-06-20 10:37 ` Duan,Muquan
2023-06-08 5:47 ` Kuniyuki Iwashima
2023-06-08 6:35 ` Eric Dumazet
2023-06-19 17:03 ` Kuniyuki Iwashima
2023-06-19 17:39 ` Eric Dumazet
2023-06-19 17:58 ` Kuniyuki Iwashima
2025-09-19 10:43 ` Gou Hao
2025-07-15 7:21 Gou Hao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FD0FE67D-378D-4DDE-BB35-6FFDE2AD3AA5@baidu.com \
--to=duanmuquan@baidu.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®