[issue12378] smtplib.SMTP_SSL leaks socket connections on SSL error

Joe Shaw report at bugs.python.org
Mon Jun 20 21:59:42 CEST 2011


Joe Shaw <jshaw at itasoftware.com> added the comment:

>From some experimentation, closing the underlying socket isn't enough.  You also need to close the SSL socket, so you'd need to do something like:


new_socket = socket.create_connection((host, port), timeout)
ssl_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile, do_handshake_on_connect=False)
try:
    ssl_socket.do_handshake()
except:
    ssl_socket.close()
    new_socket.close()
    raise
self.file = SSLFakeFile(ssl_socket)
return ssl_socket

----------

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


More information about the Python-bugs-list mailing list