phihag/mockmail — Issue #6: Do not crash if port is taken
Author: phihag
Created: 2012-01-24 13:57:31+00:00
State: open

In some cases, a TCP port may stay open even if the associated application has been terminated. That can lead to errors:

Restarting :Traceback (most recent call last):
File "/usr/local/bin/mockmail", line 529, in
main()
File "/usr/local/bin/mockmail", line 510, in main
mockmail(config)
File "/usr/local/bin/mockmail", line 392, in mockmail
smtpSrv = MockmailSmtpServer(config['smtpaddr'], config['smtpport'], ms)
File "/usr/local/bin/mockmail", line 215, in __init__
smtpd.SMTPServer.__init__(self, (localaddr, port), None)
File "/usr/lib/python3.1/smtpd.py", line 289, in __init__
self.bind(localaddr)
File "/usr/lib/python3.1/asyncore.py", line 331, in bind
return self.socket.bind(addr)
socket.error: [Errno 98] Address already in use

We should do the following:

* Add a configuration option to bind the port non-exclusively by setting `SO_REUSEADDR`.
* Add a configuration option `retry_bind_after_ms` that makes mockmail try again after the specified interval. The default should be None (i.e. don't retry), but the production configuration can contain `10000` or so.