homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author joeshaw
Recipients joeshaw
Date 2011年06月20日.19:44:22
SpamBayes Score 7.976534e-09
Marked as misclassified No
Message-id <1308599064.12.0.317669798103.issue12378@psf.upfronthosting.co.za>
In-reply-to
Content
Start a non-SSL server on port 2525:
$ python -m smtpd -n -c DebuggingServer localhost:2525
In another terminal, fire up a python interpreter and run the following code:
>>> import smtplib
>>> s = smtplib.SMTP_SSL("localhost", 2525)
[...]
ssl.SSLError: [Errno 1] _ssl.c:480: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
The underlying socket connection is still open, but you can't access it or close it:
$ lsof -P -p 76318 | grep 2525
Python 76318 joeshaw 3u IPv4 0x09a9fb18 0t0 TCP localhost:64328->localhost:2525 (ESTABLISHED)
This wreaks havoc if you're trying to write a unit test using the smtpd module and asyncore in a thread and try to clean up after yourself.
The code inside SMTP_SSL looks something like this (on 2.6.5 anyway):
 def _get_socket(self, host, port, timeout):
 if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
 new_socket = socket.create_connection((host, port), timeout)
 new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
 self.file = SSLFakeFile(new_socket)
 return new_socket
Something like:
 new_socket = socket.create_connection((host, port), timeout)
 try:
 new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
 except:
 new_socket.close()
 raise
 self.file = SSLFakeFile(new_socket)
 return new_socket
I think will do the trick.
History
Date User Action Args
2011年06月20日 19:44:24joeshawsetrecipients: + joeshaw
2011年06月20日 19:44:24joeshawsetmessageid: <1308599064.12.0.317669798103.issue12378@psf.upfronthosting.co.za>
2011年06月20日 19:44:23joeshawlinkissue12378 messages
2011年06月20日 19:44:23joeshawcreate

AltStyle によって変換されたページ (->オリジナル) /