Re: [RFC] EADDRINUSE from bind() on application restart after killing

From: Eric Dumazet
Date: Mon Jun 27 2022 - 08:01:14 EST


On Mon, Jun 27, 2022 at 12:20 PM Muhammad Usama Anjum
<usama.anjum@xxxxxxxxxxxxx> wrote:
>
> Hi Eric,
>
> On 5/30/22 8:28 PM, Eric Dumazet wrote:
> >> The following command and patch work for my use case. The socket in
> >> TIME_WAIT_2 or TIME_WAIT state are closed when zapped.
> >>
> >> Can you please upstream this patch?
> > Yes, I will when net-next reopens, thanks for testing it.
> Have you tried upstreaming it?
>
> Tested-by: Muhammad Usama Anjum <usama.anjum@xxxxxxxxxxxxx>
>

I will do this today, thanks for the heads up.


> >
> >>> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> >>> index 9984d23a7f3e1353d2e1fc9053d98c77268c577e..1b7bde889096aa800b2994c64a3a68edf3b62434
> >>> 100644
> >>> --- a/net/ipv4/tcp.c
> >>> +++ b/net/ipv4/tcp.c
> >>> @@ -4519,6 +4519,15 @@ int tcp_abort(struct sock *sk, int err)
> >>> local_bh_enable();
> >>> return 0;
> >>> }
> >>> + if (sk->sk_state == TCP_TIME_WAIT) {
> >>> + struct inet_timewait_sock *tw = inet_twsk(sk);
> >>> +
> >>> + refcount_inc(&tw->tw_refcnt);
> >>> + local_bh_disable();
> >>> + inet_twsk_deschedule_put(tw);
> >>> + local_bh_enable();
> >>> + return 0;
> >>> + }
> >>> return -EOPNOTSUPP;
> >>> }
>
> --
> Muhammad Usama Anjum