]> granicus.if.org Git - python/commitdiff
Issue #8524: When creating an SSL socket, the timeout value of the
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 24 Apr 2010 22:04:40 +0000 (22:04 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 24 Apr 2010 22:04:40 +0000 (22:04 +0000)
original socket wasn't retained (instead, a socket with a positive timeout
would be turned into a non-blocking SSL socket).

Lib/ssl.py
Lib/test/test_ssl.py
Misc/NEWS

index a42643fa10e31ddf68b602aa465890e87287e61c..f06792e48199138a898ed5b49efc5ffab2ad678b 100644 (file)
@@ -102,6 +102,7 @@ class SSLSocket(socket):
                             type=sock.type,
                             proto=sock.proto,
                             fileno=_dup(sock.fileno()))
+            self.settimeout(sock.gettimeout())
             sock.close()
         elif fileno is not None:
             socket.__init__(self, fileno=fileno)
index bd2aed578b5cbbf8b54ccf6bda07791159bdad61..3c03b59d5a5e6e3db53b1d41c26a921320c3d3d5 100644 (file)
@@ -151,6 +151,15 @@ class BasicTests(unittest.TestCase):
         del ss
         self.assertEqual(wr(), None)
 
+    def test_timeout(self):
+        # Issue #8524: when creating an SSL socket, the timeout of the
+        # original socket should be retained.
+        for timeout in (None, 0.0, 5.0):
+            s = socket.socket(socket.AF_INET)
+            s.settimeout(timeout)
+            ss = ssl.wrap_socket(s)
+            self.assertEqual(timeout, ss.gettimeout())
+
 
 class NetworkedTests(unittest.TestCase):
 
@@ -1306,17 +1315,15 @@ else:
             started.wait()
 
             try:
-                if 0:
-                    # Disabled until #8524 finds a solution
-                    try:
-                        c = socket.socket(socket.AF_INET)
-                        c.settimeout(1.0)
-                        c.connect((host, port))
-                        # Will attempt handshake and time out
-                        self.assertRaisesRegexp(ssl.SSLError, "timed out",
-                                                ssl.wrap_socket, c)
-                    finally:
-                        c.close()
+                try:
+                    c = socket.socket(socket.AF_INET)
+                    c.settimeout(0.2)
+                    c.connect((host, port))
+                    # Will attempt handshake and time out
+                    self.assertRaisesRegexp(ssl.SSLError, "timed out",
+                                            ssl.wrap_socket, c)
+                finally:
+                    c.close()
                 try:
                     c = socket.socket(socket.AF_INET)
                     c = ssl.wrap_socket(c)
index e98e95d5ffd3efc2ba36394b80919ac3e7a8e960..fb97f53df346ce6043e67c83808557db1d7e9ee7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -339,6 +339,10 @@ C-API
 Library
 -------
 
+- Issue #8524: When creating an SSL socket, the timeout value of the
+  original socket wasn't retained (instead, a socket with a positive timeout
+  would be turned into a non-blocking SSL socket).
+
 - Issue #5103: SSL handshake would ignore the socket timeout and block
   indefinitely if the other end didn't respond.