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

Skip to content

Commit cfcd8ad

Browse files
committed
Note: I'm just merging in the additional test.
Merged revisions 80428 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r80428 | antoine.pitrou | 2010-04-24 01:25:45 +0200 (sam., 24 avril 2010) | 4 lines Issue #5238: Calling makefile() on an SSL object would prevent the underlying socket from being closed until all objects get truely destroyed. ........
1 parent 9d54366 commit cfcd8ad

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import socket
77
import select
88
import time
9+
import gc
910
import os
11+
import errno
1012
import pprint
1113
import urllib.parse, urllib.request
1214
import traceback
@@ -149,6 +151,22 @@ def test_refcycle(self):
149151
del ss
150152
self.assertEqual(wr(), None)
151153

154+
def test_makefile_close(self):
155+
# Issue #5238: creating a file-like object with makefile() shouldn't
156+
# leak the underlying file descriptor.
157+
ss = ssl.wrap_socket(socket.socket(socket.AF_INET))
158+
fd = ss.fileno()
159+
f = ss.makefile()
160+
f.close()
161+
# The fd is still open
162+
os.read(fd, 0)
163+
# Closing the SSL socket should close the fd too
164+
ss.close()
165+
gc.collect()
166+
with self.assertRaises(OSError) as e:
167+
os.read(fd, 0)
168+
self.assertEqual(e.exception.errno, errno.EBADF)
169+
152170

153171
class NetworkedTests(unittest.TestCase):
154172

0 commit comments

Comments
 (0)