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

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Sat Sep 18 08:23:29 EDT 2010


In message <i72a7a$drk$1 at reader1.panix.com>, Grant Edwards wrote:

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

I’m not so sure about that. I’ve done a bunch of development on a system 
recently which had a server process written in Python running on a Linux 
box, accepting connections from a client running under old MacOS 9 (don’t 
ask) which was, of course, prone to crash.

If the client had shut down cleanly, then I could stop and restart the 
server process without any problems reopening the socket. But if I forgot to 
close the client, then the server would hit the “already in use” error.

To deal with it, I simply put in an automatic retry at 60-second intervals 
until it succeeded in reopening the socket.



More information about the Python-list mailing list