Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use')

Discussion in 'Python' started by Steve Holden, Feb 1, 2009.

  1. Steve Holden

    Steve Holden Guest

    Laszlo Nagy wrote:
    >
    >> 8<------------------------------
    >>
    >>
    >>> ....... Setting the
    >>> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows,
    >>> though).
    >>>

    >>
    >> Why not? I have been merrily setting it, and I have not noticed
    >> anything weird.
    >> (yet)
    >>

    > Please see my original post. I specifically stated that I do not want to
    > use setsockopt and be able to listen on the same port from many
    > processes. I knew that I could use SO_REUSEADDR, but I'm heistating to
    > do so. I must guarantee that only one process listens on a given port at
    > the same time.
    >

    This appears to demonstrate a misunderstanding of the purpose of the
    SO_REUSEADDR flag.

    SO_REUSEADDR should be used to avoid the TIME_WAIT state when the
    current listening process terminates. If you do not use it then there
    will be a certain period during which no other process can listen on
    that port, and it will be reusable only after the TIME_WAIT is over.
    This can easily be seen by using the netstat utility.

    See "Pitfall 3" in

    http://www.ibm.com/developerworks/linux/library/l-sockpit/index.html

    > Maybe I could use some kind of locking, but it would be too difficult:
    >
    > - mutexes are great but they are platform dependent and they are not in
    > the standard lib
    > - the listening processes do not see each other's home directory so file
    > locking cannot be used for this
    > - these processes will probably listen on many ports at the same time,
    > it is also a problem with mutexes/file locks (who wants 50 lock files to
    > be created?)
    >

    Complete red herring: there is no way for multiple processes to listen
    to the same port: this would lead to ambiguity in the protocol stack.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Feb 1, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Nagy
    Replies:
    1
    Views:
    4,915
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    990
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    564
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    1
    Views:
    729
  5. Hendrik van Rooyen
    Replies:
    0
    Views:
    577
    Hendrik van Rooyen
    Feb 2, 2009
Loading...

Share This Page