-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
smtpd.SMTPServer can cause asyncore.loop to enter infinite event loop #50838
Comments
When subclass of smtpd.SMTPServer, it is possible the get asyncore.loop ..... To reproduce:
Analysis: Workaround and Proposed Fix: class MySmtpServer( smtpd.SMTPServer, object ):
def __init__( self, **kwargs ):
try:
super( _SmtpSink, self).__init__(**kwargs)
except Exception as e:
self.close() # cleanup asyncore after failure
raise For a long term fix, I would recommend performing the |
Could you provide an actual example code which reproduces this problem? Furthermore the use case you have described it's pretty uncommon as you shouldn't run SMTPServer in a thread in the first place. If you intend to bind two servers simultaneously you just have to instantiate two STMPServer sub/classes and finally call asyncore.loop(). |
This is how it gets in an "invalid state". Not sure why you can't look at the code and see the mistake. "There is no code in the As far as running in a thread. I have a program that needs must start and stop the SMTPServer dynamically. I did this by putting SMTPServer in a thread. Maybe there is another way to do it, but if you are not going to support this, then it should be documented. |
If you can provide a short example that reproduces the problem it will be much more likely to get fixed. |
I attached a simple script that reproduces the report issue. I hope it helps. |
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. |
Patch in attachment. |
Fixed in r82404, r82406, r82407 and r82408. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: