OSError: [Errno 48] Address already in use

Dan Stromberg drsalists at gmail.com
Thu Jun 28 15:00:39 EDT 2018


On Wed, Jun 27, 2018 at 8:49 AM, T Berger <brgrt2 at gmail.com> wrote:

> Why am I getting this error? I'm not sure what additional information I
> need to supply, so please let me know.


AIUI, there are 2 possible causes.  You either have some other process
listening on the requested port, or a process that Was using it no longer
is but not enough time has passed yet for the kernel to decide that the
port can safely be reused.

The former keeps two processes from trying to get data from the same port
at the same time, which could be confusing.

The latter is a security feature.  It keeps person A from starting an imap
server on port tcp/5555, and having person B come along and start a fake,
password-stealing imap server on the same port shortly after person A
terminates theirs (for example). There would otherwise be a window of time
during which B's imap daemon could steal passwords intended for A's imap
daemon, because remote imap clients wouldn't know about the switcheroo.
Note that even if A come back and starts their imap daemon immediately
after a crash, the kernel doesn't know if that is a legitimate or
illegitemate imap daemon, so that is blocked for a while too.

You can check if something else is listening on that port with
http://stromberg.dnsalias.org/~strombrg/What-program-is-active-on-that-port.html
(Linux and Solaris - there will likely be similar tools for other OS's).

You can eliminate the waiting period with SO_REUSEADDR (but if you have
something else listening on that port, then don't!). Example:
http://stromberg.dnsalias.org/~strombrg/max-tcp-window.html

HTH.



More information about the Python-list mailing list