Index: Lib/socket.py =================================================================== --- Lib/socket.py (revision 54542) +++ Lib/socket.py (working copy) @@ -145,6 +145,10 @@ send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy __getattr__ = _dummy +# Wrapper around platform socket objects. This implements +# a platform-independent dup() functionality. The +# implementation currently relies on reference counting +# to close the underlying socket object. class _socketobject(object): __doc__ = _realsocket.__doc__ Index: Lib/httplib.py =================================================================== --- Lib/httplib.py (revision 54542) +++ Lib/httplib.py (working copy) @@ -1133,6 +1133,9 @@ def __getattr__(self, attr): return getattr(self._sock, attr) + def close(self): + SharedSocketClient.close(self) + self._ssl = None class HTTPSConnection(HTTPConnection): "This class allows communication via SSL." Index: Lib/test/test_socket_ssl.py =================================================================== --- Lib/test/test_socket_ssl.py (revision 54542) +++ Lib/test/test_socket_ssl.py (working copy) @@ -118,12 +118,32 @@ connector() t.join() +def test_978833(): + if test_support.verbose: + print "test_978833 ..." + + import os, httplib + with test_support.transient_internet(): + s = socket.socket(socket.AF_INET) + s.connect(("www.sf.net", 443)) + fd = s._sock.fileno() + sock = httplib.FakeSocket(s, socket.ssl(s)) + s = None + sock.close() + try: + os.fstat(fd) + except OSError: + pass + else: + raise test_support.TestFailed("Failed to close socket") + def test_main(): if not hasattr(socket, "ssl"): raise test_support.TestSkipped("socket module has no ssl support") test_rude_shutdown() test_basic() test_timeout() + test_978833() if __name__ == "__main__": test_main()