All of lore.kernel.org
 help / color / mirror / Atom feed
* Error binding socket: address already in use
@ 2006-09-13 14:41 Peter Lezoch
  2006-09-13 14:46 ` Jan Engelhardt
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Peter Lezoch @ 2006-09-13 14:41 UTC (permalink / raw)
  To: linux-kernel


Hi,
killing a server task that is operating on a UDP socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. A subsequently started task, that wants to use the same port, gets from bind above error message.This is, in my opinion, wrong behavior, because of the connectionless nature of UDP. Only reboot solves this situation. It looks, as if in net/socket.c, TCP and UDP are handled in the same way without taking into account the different nature of the protocols?!
How can I overcome this problem ?

kind regards

peter lezoch

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

* Re: Error binding socket: address already in use
  2006-09-13 14:41 Error binding socket: address already in use Peter Lezoch
@ 2006-09-13 14:46 ` Jan Engelhardt
  2006-09-13 14:46 ` David M. Lloyd
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jan Engelhardt @ 2006-09-13 14:46 UTC (permalink / raw)
  To: Peter Lezoch; +Cc: linux-kernel


>Hi,
>killing a server task that is operating on a UDP socket( AF_INET, 
>SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. A 
>subsequently started task, that wants to use the same port, gets from 
>bind above error message.This is, in my opinion, wrong behavior, 

man setsockopt
Look for SO_REUSEADDR
It is all correct behavior.

>because of the connectionless nature of UDP. Only reboot solves this 

Waiting a while should also solve this.

>situation. It looks, as if in net/socket.c, TCP and UDP are handled in 
>the same way without taking into account the different nature of the 
>protocols?!
>How can I overcome this problem ?

Jan Engelhardt
-- 

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

* Re: Error binding socket: address already in use
  2006-09-13 14:41 Error binding socket: address already in use Peter Lezoch
  2006-09-13 14:46 ` Jan Engelhardt
@ 2006-09-13 14:46 ` David M. Lloyd
  2006-09-13 15:23 ` Alan Cox
  2006-09-13 15:33 ` linux-os (Dick Johnson)
  3 siblings, 0 replies; 6+ messages in thread
From: David M. Lloyd @ 2006-09-13 14:46 UTC (permalink / raw)
  To: Peter Lezoch; +Cc: linux-kernel

On Wed, 2006-09-13 at 14:41 +0000, Peter Lezoch wrote:
> Hi,
> killing a server task that is operating on a UDP socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. A subsequently started task, that wants to use the same port, gets from bind above error message.This is, in my opinion, wrong behavior, because of the connectionless nature of UDP. Only reboot solves this situation. It looks, as if in net/socket.c, TCP and UDP are handled in the same way without taking into account the different nature of the protocols?!
> How can I overcome this problem ?

Perhaps SO_REUSEADDR is what you're looking for?

man 7 socket

- DML


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

* Re: Error binding socket: address already in use
  2006-09-13 14:41 Error binding socket: address already in use Peter Lezoch
  2006-09-13 14:46 ` Jan Engelhardt
  2006-09-13 14:46 ` David M. Lloyd
@ 2006-09-13 15:23 ` Alan Cox
  2006-09-14  7:15   ` Colin Hirsch
  2006-09-13 15:33 ` linux-os (Dick Johnson)
  3 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2006-09-13 15:23 UTC (permalink / raw)
  To: Peter Lezoch; +Cc: linux-kernel

Ar Mer, 2006-09-13 am 14:41 +0000, ysgrifennodd Peter Lezoch:
> Hi,
> killing a server task that is operating on a UDP socket( AF_INET,
> SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. 

For UDP the socket closes at the point the last user of the socket
closes. For TCP there is a time delay mandated by the specification.

If you are seeing UDP sockets remain open when you kill a server make
sure it hasn't forked other processes and passed them the file handle.


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

* Re: Error binding socket: address already in use
  2006-09-13 14:41 Error binding socket: address already in use Peter Lezoch
                   ` (2 preceding siblings ...)
  2006-09-13 15:23 ` Alan Cox
@ 2006-09-13 15:33 ` linux-os (Dick Johnson)
  3 siblings, 0 replies; 6+ messages in thread
From: linux-os (Dick Johnson) @ 2006-09-13 15:33 UTC (permalink / raw)
  To: Peter Lezoch; +Cc: linux-kernel


On Wed, 13 Sep 2006, Peter Lezoch wrote:

>
> Hi,
> killing a server task that is operating on a UDP socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. A subsequently started task, that wants to use the same port, gets from bind above error message.This is, in my opinion, wrong behavior, because of the connectionless nature of UDP. Only reboot solves this situation. It looks, as if in net/socket.c, TCP and UDP are handled in the same way without taking into account the different nature of the protocols?!
> How can I overcome this problem ?
>
> kind regards
>
> peter lezoch


Try:
  int opt = 1;
  setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 on an i686 machine (5592.66 BogoMips).
New book: http://www.AbominableFirebug.com/
_
\x1a\x04

****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

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

* Re: Error binding socket: address already in use
  2006-09-13 15:23 ` Alan Cox
@ 2006-09-14  7:15   ` Colin Hirsch
  0 siblings, 0 replies; 6+ messages in thread
From: Colin Hirsch @ 2006-09-14  7:15 UTC (permalink / raw)
  To: linux-kernel

On Wed, Sep 13, 2006 at 04:23:35PM +0100, Alan Cox wrote:
> Ar Mer, 2006-09-13 am 14:41 +0000, ysgrifennodd Peter Lezoch:
> > Hi,
> > killing a server task that is operating on a UDP socket( AF_INET,
> > SOCK_DGRAM, IPPROTO_UDP ), leaves the socket in an unclosed state. 
> 
> For UDP the socket closes at the point the last user of the socket
> closes. For TCP there is a time delay mandated by the specification.
> 
> If you are seeing UDP sockets remain open when you kill a server make
> sure it hasn't forked other processes and passed them the file handle.

Additional note on REUSEADDR: The standard semantics of REUSEADDR on a
UDP socket is to allow several sockets to bind to the same address
simultaneously (!), i.e. if your server uses it you can start it several
times on the same socket, which is not what one normally wants.

Regards, Colin


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

end of thread, other threads:[~2006-09-14  7:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 14:41 Error binding socket: address already in use Peter Lezoch
2006-09-13 14:46 ` Jan Engelhardt
2006-09-13 14:46 ` David M. Lloyd
2006-09-13 15:23 ` Alan Cox
2006-09-14  7:15   ` Colin Hirsch
2006-09-13 15:33 ` linux-os (Dick Johnson)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.