netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Eric Dumazet <edumazet@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	David Ahern <dsahern@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"open list:NETWORKING [TCP]" <netdev@vger.kernel.org>
Cc: usama.anjum@collabora.com,
	Gabriel Krisman Bertazi <krisman@collabora.com>,
	LKML <linux-kernel@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: [RFC] EADDRINUSE from bind() on application restart after killing
Date: Tue, 24 May 2022 13:18:55 +0500	[thread overview]
Message-ID: <5099dc39-c6d9-115a-855b-6aa98d17eb4b@collabora.com> (raw)

Hello,

We have a set of processes which talk with each other through a local
TCP socket. If the process(es) are killed (through SIGKILL) and
restarted at once, the bind() fails with EADDRINUSE error. This error
only appears if application is restarted at once without waiting for 60
seconds or more. It seems that there is some timeout of 60 seconds for
which the previous TCP connection remains alive waiting to get closed
completely. In that duration if we try to connect again, we get the error.

We are able to avoid this error by adding SO_REUSEADDR attribute to the
socket in a hack. But this hack cannot be added to the application
process as we don't own it.

I've looked at the TCP connection states after killing processes in
different ways. The TCP connection ends up in 2 different states with
timeouts:

(1) Timeout associated with FIN_WAIT_1 state which is set through
`tcp_fin_timeout` in procfs (60 seconds by default)

(2) Timeout associated with TIME_WAIT state which cannot be changed. It
seems like this timeout has come from RFC 1337.

The timeout in (1) can be changed. Timeout in (2) cannot be changed. It
also doesn't seem feasible to change the timeout of TIME_WAIT state as
the RFC mentions several hazards. But we are talking about a local TCP
connection where maybe those hazards aren't applicable directly? Is it
possible to change timeout for TIME_WAIT state for only local
connections without any hazards?

We have tested a hack where we replace timeout of TIME_WAIT state from a
value in procfs for local connections. This solves our problem and
application starts to work without any modifications to it.

The question is that what can be the best possible solution here? Any
thoughts will be very helpful.

Regards,

-- 
Muhammad Usama Anjum

             reply	other threads:[~2022-05-24  8:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24  8:18 Muhammad Usama Anjum [this message]
2022-05-24 22:13 ` [RFC] EADDRINUSE from bind() on application restart after killing Eric Dumazet
2022-05-30 13:15   ` Muhammad Usama Anjum
2022-05-30 15:28     ` Eric Dumazet
2022-06-27 10:20       ` Muhammad Usama Anjum
2022-06-27 11:47         ` Eric Dumazet
2022-09-30 13:24 ` Muhammad Usama Anjum
2022-09-30 15:16   ` Eric Dumazet
2022-10-14 15:52     ` Paul Gofman
2022-10-14 16:20       ` Eric Dumazet
2022-10-14 16:31         ` Paul Gofman
2022-10-14 16:34           ` Eric Dumazet
2022-10-14 16:39             ` Paul Gofman
2022-10-14 16:45               ` Eric Dumazet
2022-10-14 17:20                 ` Paul Gofman

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=5099dc39-c6d9-115a-855b-6aa98d17eb4b@collabora.com \
    --to=usama.anjum@collabora.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=krisman@collabora.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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;
as well as URLs for NNTP newsgroup(s).