Kaydet (Commit) 40f0874b authored tarafından Antoine Pitrou's avatar Antoine Pitrou

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).
üst d3f8ab8b
...@@ -102,6 +102,7 @@ class SSLSocket(socket): ...@@ -102,6 +102,7 @@ class SSLSocket(socket):
type=sock.type, type=sock.type,
proto=sock.proto, proto=sock.proto,
fileno=_dup(sock.fileno())) fileno=_dup(sock.fileno()))
self.settimeout(sock.gettimeout())
sock.close() sock.close()
elif fileno is not None: elif fileno is not None:
socket.__init__(self, fileno=fileno) socket.__init__(self, fileno=fileno)
......
...@@ -151,6 +151,15 @@ class BasicTests(unittest.TestCase): ...@@ -151,6 +151,15 @@ class BasicTests(unittest.TestCase):
del ss del ss
self.assertEqual(wr(), None) 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): class NetworkedTests(unittest.TestCase):
...@@ -1306,17 +1315,15 @@ else: ...@@ -1306,17 +1315,15 @@ else:
started.wait() started.wait()
try: try:
if 0: try:
# Disabled until #8524 finds a solution c = socket.socket(socket.AF_INET)
try: c.settimeout(0.2)
c = socket.socket(socket.AF_INET) c.connect((host, port))
c.settimeout(1.0) # Will attempt handshake and time out
c.connect((host, port)) self.assertRaisesRegexp(ssl.SSLError, "timed out",
# Will attempt handshake and time out ssl.wrap_socket, c)
self.assertRaisesRegexp(ssl.SSLError, "timed out", finally:
ssl.wrap_socket, c) c.close()
finally:
c.close()
try: try:
c = socket.socket(socket.AF_INET) c = socket.socket(socket.AF_INET)
c = ssl.wrap_socket(c) c = ssl.wrap_socket(c)
......
...@@ -339,6 +339,10 @@ C-API ...@@ -339,6 +339,10 @@ C-API
Library 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 - Issue #5103: SSL handshake would ignore the socket timeout and block
indefinitely if the other end didn't respond. indefinitely if the other end didn't respond.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment