[issue6589] smtpd.SMTPServer can cause asyncore.loop to enter infinite event loop

Giampaolo Rodola' report at bugs.python.org
Wed Jun 30 13:38:59 CEST 2010


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

Although the use case is pretty uncommon and somewhat twisted (take a look at Lib/test/test_ftplib.py for a nicer approach on wrapping asyncore.loop() in a thread) it is true that if SMTPServer class raise an exception at instantiation time, some garbage remains in asyncore.

To replicate this problem there's no need to involve threads:

>>> import asyncore, smtpd
>>> s = smtpd.SMTPServer(('127.0.0.1', "xxx"),None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/smtpd.py", line 280, in __init__
    self.bind(localaddr)
  File "/usr/local/lib/python2.5/asyncore.py", line 303, in bind
    return self.socket.bind(addr)
  File "<string>", line 1, in bind
TypeError: an integer is required
>>> asyncore.socket_map
{3: <smtpd.SMTPServer ('127.0.0.1', 'xxx') at 0xb783528c>}
>>> 

I think it's ok for SMTPServer.__init__ to cleanup asyncore and finally raise the exception, as you suggested in the first place.
I'll provide a patch later today.

----------
assignee:  -> giampaolo.rodola
versions: +Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6589>
_______________________________________


More information about the Python-bugs-list mailing list