Message138753
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. |
|
Date |
User |
Action |
Args |
2011-06-20 19:44:24 | joeshaw | set | recipients:
+ joeshaw |
2011-06-20 19:44:24 | joeshaw | set | messageid: <1308599064.12.0.317669798103.issue12378@psf.upfronthosting.co.za> |
2011-06-20 19:44:23 | joeshaw | link | issue12378 messages |
2011-06-20 19:44:23 | joeshaw | create | |
|