socket.error: [Errno 98] Address already in use

Jorgen Grahn grahn+nntp at
Sun Sep 19 01:29:33 CEST 2010

On Sat, 2010-09-18, Lawrence D'Oliveiro wrote:
> In message 
> <2f830099-4264-47bc-98ee-31950412ad43 at>, cerr 
> wrote:
>> I get a socket error "[Errno 98] Address already in use" when i try to
>> open a socket that got closed before with close(). How come close()
>> doesn't close the socket properly?
> The usual case this happens is you have a client connection open at the 
> time, that was not properly terminated. Then the TCP stack goes through a 
> holdoff period (2 minutes, I believe it is), to make absolutely sure all 
> packets destined for the old connection have completely disappeared off the 
> entire Internet, before it will let you open a socket on the same port 
> again.

That's why Stevens recommends that all TCP servers use the
SO_REUSEADDR socket option.  He also noted in his book:

    "This scenario is one of the most frequently asked
    questions on Usenet."

Possibly I missed something in the question, but it's worth googling for.


  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/>   O  o   .

More information about the Python-list mailing list