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

Skip to content

Commit dc020cc

Browse files
miss-islingtonpablogsal
authored andcommitted
Make sure file object is close if socket.create_connection fails (GH-11334) (GH-11351)
The problem affects _testWithTimeoutTriggeredSend in test_socket.py. (cherry picked from commit 1f511e1) Co-authored-by: Pablo Galindo <[email protected]>
1 parent 7eef540 commit dc020cc

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Lib/test/test_socket.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5363,11 +5363,10 @@ def testWithTimeout(self):
53635363

53645364
def _testWithTimeoutTriggeredSend(self):
53655365
address = self.serv.getsockname()
5366-
file = open(support.TESTFN, 'rb')
5367-
with socket.create_connection(address, timeout=0.01) as sock, \
5368-
file as file:
5369-
meth = self.meth_from_sock(sock)
5370-
self.assertRaises(socket.timeout, meth, file)
5366+
with open(support.TESTFN, 'rb') as file:
5367+
with socket.create_connection(address, timeout=0.01) as sock:
5368+
meth = self.meth_from_sock(sock)
5369+
self.assertRaises(socket.timeout, meth, file)
53715370

53725371
def testWithTimeoutTriggeredSend(self):
53735372
conn = self.accept_conn()

0 commit comments

Comments
 (0)