Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2203f9

Browse files
committed
Merged revisions 80456 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r80456 | antoine.pitrou | 2010-04-25 00:04:40 +0200 (dim., 25 avril 2010) | 5 lines 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). ........
1 parent ec14618 commit c2203f9

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

Lib/ssl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def __init__(self, sock=None, keyfile=None, certfile=None,
101101
type=sock.type,
102102
proto=sock.proto,
103103
fileno=_dup(sock.fileno()))
104+
self.settimeout(sock.gettimeout())
104105
sock.close()
105106
elif fileno is not None:
106107
socket.__init__(self, fileno=fileno)

Lib/test/test_ssl.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def test_refcycle(self):
110110
del ss
111111
self.assertEqual(wr(), None)
112112

113+
def test_timeout(self):
114+
# Issue #8524: when creating an SSL socket, the timeout of the
115+
# original socket should be retained.
116+
for timeout in (None, 0.0, 5.0):
117+
s = socket.socket(socket.AF_INET)
118+
s.settimeout(timeout)
119+
ss = ssl.wrap_socket(s)
120+
self.assertEqual(timeout, ss.gettimeout())
121+
113122

114123
class NetworkedTests(unittest.TestCase):
115124

@@ -1262,17 +1271,15 @@ def serve():
12621271
started.wait()
12631272

12641273
try:
1265-
if 0:
1266-
# Disabled until #8524 finds a solution
1267-
try:
1268-
c = socket.socket(socket.AF_INET)
1269-
c.settimeout(1.0)
1270-
c.connect((host, port))
1271-
# Will attempt handshake and time out
1272-
self.assertRaisesRegexp(ssl.SSLError, "timed out",
1273-
ssl.wrap_socket, c)
1274-
finally:
1275-
c.close()
1274+
try:
1275+
c = socket.socket(socket.AF_INET)
1276+
c.settimeout(0.2)
1277+
c.connect((host, port))
1278+
# Will attempt handshake and time out
1279+
self.assertRaisesRegexp(ssl.SSLError, "timed out",
1280+
ssl.wrap_socket, c)
1281+
finally:
1282+
c.close()
12761283
try:
12771284
c = socket.socket(socket.AF_INET)
12781285
c = ssl.wrap_socket(c)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Core and Builtins
4040
Library
4141
-------
4242

43+
- Issue #8524: When creating an SSL socket, the timeout value of the
44+
original socket wasn't retained (instead, a socket with a positive timeout
45+
would be turned into a non-blocking SSL socket).
46+
4347
- Issue #5103: SSL handshake would ignore the socket timeout and block
4448
indefinitely if the other end didn't respond.
4549

0 commit comments

Comments
 (0)