netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bind() should not return -EADDRINUSE
@ 2014-12-11 19:19 Phillip Susi
  2014-12-11 19:23 ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Phillip Susi @ 2014-12-11 19:19 UTC (permalink / raw)
  To: netdev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attempting to establish a connection to a remote host using the same
local port, but a different remote port as the previous connection (
that is still in TIME_WAIT ) results in bind() returning -EADDRINUSE.
 By changing the remote port, you avoid the conflict with the other
connection that is in TIME_WAIT, but since the remote port is not
known when bind() is called, it incorrectly returns -EADDRINUSE.  This
check should not be done in bind(), but deferred until the remote port
is known in the call to connect(), or listen().

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJUie4vAAoJENRVrw2cjl5R8CgH/jgdrBXs1Yso7XsHtrsUgO75
P8bY3Mf8eOuAkLvwbHopyGr19UZJJ+5zCQWc6bus9BRa7jSQvPCRw8fSjg3u+NXs
r9/qEqiDrYwAJqV5SwqDPGU8xGwq8v31bbT09spGIL9fABW3krBFtDHcZ/PzGA/p
UGDgELdkU7QIMKvC7FAV5RzvMXpmAI+m7iQiF936QkGZPN0AOCTea0sB+IpeidTO
/ChLd2iaEqAmS6UGh3jIQSNcTB3Ho3imHHMjTCel2v8+SgCBb2Tp3HzfmmIsGAnh
YeH+ZCNHD08c+k9yprEVjCH6fwMOo7CWzyPnSme+Ggk0L5r9oj8iz4xIeIMv43o=
=Ou3S
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 19:19 bind() should not return -EADDRINUSE Phillip Susi
@ 2014-12-11 19:23 ` David Miller
  2014-12-11 19:50   ` Phillip Susi
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2014-12-11 19:23 UTC (permalink / raw)
  To: psusi; +Cc: netdev

From: Phillip Susi <psusi@ubuntu.com>
Date: Thu, 11 Dec 2014 14:19:11 -0500

> Attempting to establish a connection to a remote host using the same
> local port, but a different remote port as the previous connection (
> that is still in TIME_WAIT ) results in bind() returning -EADDRINUSE.
>  By changing the remote port, you avoid the conflict with the other
> connection that is in TIME_WAIT, but since the remote port is not
> known when bind() is called, it incorrectly returns -EADDRINUSE.  This
> check should not be done in bind(), but deferred until the remote port
> is known in the call to connect(), or listen().

Bind has to allocate and hold from everyone else on the system the
local port at bind() time, so we cannot defer this decision.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 19:23 ` David Miller
@ 2014-12-11 19:50   ` Phillip Susi
  2014-12-11 20:13     ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Phillip Susi @ 2014-12-11 19:50 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/11/2014 2:23 PM, David Miller wrote:
> From: Phillip Susi <psusi@ubuntu.com> Date: Thu, 11 Dec 2014
> 14:19:11 -0500
> 
>> Attempting to establish a connection to a remote host using the
>> same local port, but a different remote port as the previous
>> connection ( that is still in TIME_WAIT ) results in bind()
>> returning -EADDRINUSE. By changing the remote port, you avoid the
>> conflict with the other connection that is in TIME_WAIT, but
>> since the remote port is not known when bind() is called, it
>> incorrectly returns -EADDRINUSE.  This check should not be done
>> in bind(), but deferred until the remote port is known in the
>> call to connect(), or listen().
> 
> Bind has to allocate and hold from everyone else on the system the 
> local port at bind() time, so we cannot defer this decision.

What on earth for?  If two processes are going to connect to different
remotes using the same source, that is perfectly fine.  The only
contention is if two processes want to listen() with the same local
addr and wildcard remote.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJUifWYAAoJENRVrw2cjl5RpckH/2g9V0p3SFNvf1qmR1nxZjJ6
R19eosdoWvCL6B2pIqwvpy64ACqTf6MS3NrdZt6TwSz+8OKqBj/D8+IpKcAdo5kU
Yzhl3qASkm17HTeOmGhw00pqJkD4FYzzwb8hw/OxwxWUwpVLvv+nMYHhF7vwgOy6
h90Kmj6ycOeY/+sX5Woe5RheKq+AlDqJGAELk1Vs9lrRDDa/3o/HqEQX5HNsohyC
ib2dJRAdCuNN9KjSKuVLnCu4Tf1UB5W+efSK21qN/s1r0a0RWXMe2ph6JrYQsg2e
H2nl7Ifiv/4VbuvRkabSsrge8bJtw76c2uMpxw1GHNUN1rNnxhGAj4J1oOIp4rQ=
=LXdQ
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 19:50   ` Phillip Susi
@ 2014-12-11 20:13     ` David Miller
  2014-12-11 20:17       ` Phillip Susi
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2014-12-11 20:13 UTC (permalink / raw)
  To: psusi; +Cc: netdev

From: Phillip Susi <psusi@ubuntu.com>
Date: Thu, 11 Dec 2014 14:50:48 -0500

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 12/11/2014 2:23 PM, David Miller wrote:
>> From: Phillip Susi <psusi@ubuntu.com> Date: Thu, 11 Dec 2014
>> 14:19:11 -0500
>> 
>>> Attempting to establish a connection to a remote host using the
>>> same local port, but a different remote port as the previous
>>> connection ( that is still in TIME_WAIT ) results in bind()
>>> returning -EADDRINUSE. By changing the remote port, you avoid the
>>> conflict with the other connection that is in TIME_WAIT, but
>>> since the remote port is not known when bind() is called, it
>>> incorrectly returns -EADDRINUSE.  This check should not be done
>>> in bind(), but deferred until the remote port is known in the
>>> call to connect(), or listen().
>> 
>> Bind has to allocate and hold from everyone else on the system the 
>> local port at bind() time, so we cannot defer this decision.
> 
> What on earth for?  If two processes are going to connect to different
> remotes using the same source, that is perfectly fine.  The only
> contention is if two processes want to listen() with the same local
> addr and wildcard remote.

But you don't know ahead of time what the processes are going to
do, that's the problem.

You cannot leave the port available and pretend to another process
that he will be able to use it.

Port allocation failures must be signalled at bind() time.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 20:13     ` David Miller
@ 2014-12-11 20:17       ` Phillip Susi
  2014-12-11 20:18         ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Phillip Susi @ 2014-12-11 20:17 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/11/2014 3:13 PM, David Miller wrote:
> 
> But you don't know ahead of time what the processes are going to 
> do, that's the problem.
> 
> You cannot leave the port available and pretend to another process 
> that he will be able to use it.
> 
> Port allocation failures must be signalled at bind() time.

Says who?  The man pages for both listen() and connect() say they can
return EADDRINUSE.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJUifvIAAoJENRVrw2cjl5R+r8H/jb84r9KUgMQcfFAPB4aYQKt
ou188Bpv6aa1AB1yt99il8bulvXMO5m0NuLG8NcYIDnt0zo1xaVrbxelNHIkx0XQ
Gj67Ozc+yMOQ6izHUPMNgB9lI3q/GBhI6dt5/5NnIeAx4VzCQIhT1nKT6LRo4J6z
k6R7vyXrm9M7X0A3hh7Dpapv/JWuzZfZYOZP+JQP/BSLorEX0+pZHoqOl0Cy+bwo
rp/oaAAaQe+cX95dplXLVmXoh6JxjBTkXqWEEHTnNNbz3LsY+e7aokz3Pl9kQw3M
hn1q9PSC+JMhxCI3AOgukIwlK3ps7y78PiQHxds/K/ZNVzaaeJAY+FryppUijPk=
=/oDW
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 20:17       ` Phillip Susi
@ 2014-12-11 20:18         ` David Miller
  2014-12-11 20:23           ` Phillip Susi
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2014-12-11 20:18 UTC (permalink / raw)
  To: psusi; +Cc: netdev

From: Phillip Susi <psusi@ubuntu.com>
Date: Thu, 11 Dec 2014 15:17:12 -0500

> Says who?

Says multiple decades of precendence.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 20:18         ` David Miller
@ 2014-12-11 20:23           ` Phillip Susi
  2014-12-11 20:25             ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Phillip Susi @ 2014-12-11 20:23 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/11/2014 3:18 PM, David Miller wrote:
> From: Phillip Susi <psusi@ubuntu.com> Date: Thu, 11 Dec 2014
> 15:17:12 -0500
> 
>> Says who?
> 
> Says multiple decades of precendence.

"It has always been broken, so it should stay broken" isn't a very
compelling argument.

Would it cause programs to break if they get the error at listen()
time instead of bind() time ( as the man page indicates it can )?  I
think not.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJUif1OAAoJENRVrw2cjl5RW8YH/0Rmg3JXGHJZr/z9H56F0Tfo
m9mGM5THOUIXFaCugiqea/6Y9j1qvZC4OJdoB8Ve/bDTpTa2bs3SHd81eEntVpGI
hXoeMw5RQxUuiBpKLmkWp+ma8Cl01qIADkTdRG2F/pPa8ee9xd4Lx0UGV6skUnVP
6HVuqeNxPS1xESQMpUAgO8KLGkvzB1/y8+7iBuc0fINZuox4KX8CVwzQB7d9I+G1
gf+yMaFtsDnNeGrXLKdSj7q+/yV61AgigSt3IeFIdUz+trbZa2W/6vUkBqVPB9bo
QEClO9JROTIkkl2ErUyd+bnrKTNJR0/tkOUmqf8JjQhjSnozD/u0JdoQRMvjQtk=
=PUUw
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 20:23           ` Phillip Susi
@ 2014-12-11 20:25             ` David Miller
  2014-12-11 21:34               ` Phillip Susi
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2014-12-11 20:25 UTC (permalink / raw)
  To: psusi; +Cc: netdev

From: Phillip Susi <psusi@ubuntu.com>
Date: Thu, 11 Dec 2014 15:23:45 -0500

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 12/11/2014 3:18 PM, David Miller wrote:
>> From: Phillip Susi <psusi@ubuntu.com> Date: Thu, 11 Dec 2014
>> 15:17:12 -0500
>> 
>>> Says who?
>> 
>> Says multiple decades of precendence.
> 
> "It has always been broken, so it should stay broken" isn't a very
> compelling argument.
> 
> Would it cause programs to break if they get the error at listen()
> time instead of bind() time ( as the man page indicates it can )?  I
> think not.

You will definitely break programs that look for a locally available
port by iterating over bind() calls.

Sorry, this is not changing, no matter how strongly you may wish it
to.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: bind() should not return -EADDRINUSE
  2014-12-11 20:25             ` David Miller
@ 2014-12-11 21:34               ` Phillip Susi
  0 siblings, 0 replies; 9+ messages in thread
From: Phillip Susi @ 2014-12-11 21:34 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/11/2014 3:25 PM, David Miller wrote:
> You will definitely break programs that look for a locally
> available port by iterating over bind() calls.
> 
> Sorry, this is not changing, no matter how strongly you may wish
> it to.

According to this very nice post, it is how BSD does it, at least when
you specify SO_REUSEADDR:

http://stackoverflow.com/a/14388707/884259

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJUig3WAAoJENRVrw2cjl5ROzkIAJMyXGo6OA34TFz2pXlWUlLR
+aA6UGC99oM6QV0y/sFnRGSlp4tIMTUQuFS7JzVCKHNRbm9dixtTdXLKpinBuUw/
Y1ZIO1+DyV457T05Q7w9oBxxxNqdLCRlLnVxolTiLN5IJ0mkEN+CaVJVuSl/Tx+S
YtEmCyDShpE+xwQndOUQtt0WU2ZonrKGhYH1aA6YRSyxfX1N4vTuSKqCUvsSubfm
r3tt22A6FaRey0pHzxSqzNcyvHe63THC8b556ggOcQM+yFf3C92FNyvyUWxETtdb
2VrXgGEYnXtcLXtSwYLOnQAXwW9yRg64BkinMDybVt7b6aNDG5653+Vi/NniysU=
=NxIM
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-12-11 21:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-11 19:19 bind() should not return -EADDRINUSE Phillip Susi
2014-12-11 19:23 ` David Miller
2014-12-11 19:50   ` Phillip Susi
2014-12-11 20:13     ` David Miller
2014-12-11 20:17       ` Phillip Susi
2014-12-11 20:18         ` David Miller
2014-12-11 20:23           ` Phillip Susi
2014-12-11 20:25             ` David Miller
2014-12-11 21:34               ` Phillip Susi

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).