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

Grant Edwards invalid at invalid.invalid
Sat Sep 18 08:10:18 EDT 2010


On 2010-09-18, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> In message 
><2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, 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.

Even when the connection was properly terminated (from an
application's POV), there's a TIME_WAIT period before the TCP stack
considered the connection completely gone and will allow re-use of the
port.  IOW, the TIME_WAIT is actually part of the connection
termination (from the TCP stack's POV), and it can takes place after
the application considers the connection closed (and may have even
exited):

http://www.developerweb.net/forum/showthread.php?t=2941

-- 
Grant



More information about the Python-list mailing list