]> granicus.if.org Git - python/commitdiff
Bug #978833: Close https sockets by releasing the _ssl object.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 27 Jul 2007 18:28:22 +0000 (18:28 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 27 Jul 2007 18:28:22 +0000 (18:28 +0000)
Lib/httplib.py
Lib/socket.py
Lib/test/test_socket_ssl.py
Misc/NEWS

index badaf1aadf692d66b6758528a58f80d96cb438d7..aee9b0dc03b0d8a87d5044adbb4c87884f0dc6d7 100644 (file)
@@ -1117,6 +1117,9 @@ class FakeSocket(SharedSocketClient):
     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 4490fc400d7c0c48911c6eeee02bc2f24b0a35a8..45a122fdce957aefcc8a6419896413917c56fd90 100644 (file)
@@ -144,6 +144,10 @@ class _closedsocket(object):
     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 dffa2c5aed49233193f5f16357ef0ca87c891781..e08ec4448164fead610357a1b87d706df6fb9186 100644 (file)
@@ -106,6 +106,25 @@ class BasicTests(unittest.TestCase):
         connector()
         t.join()
 
+    def test_978833(self):
+        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")
+
 class OpenSSLTests(unittest.TestCase):
 
     def testBasic(self):
index 578c2c0bf555f297233e99166c9a6c089adf93d7..4764dafd121b0808e30e0de44c74e190acea29ba 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -238,6 +238,8 @@ Core and builtins
 Library
 -------
 
+- Bug #978833: Close https sockets by releasing the _ssl object.
+
 - Change location of the package index to pypi.python.org/pypi
 
 - Bug #1701409: Fix a segfault in printing ctypes.c_char_p and