bpo-30980: Fix double close in asyncore.file_wrapper (#2789)
* bpo-30980: Fix close test to fail test_close_twice was not considering the fact that file_wrapper is duping the file descriptor. Closing the original descriptor left the duped one open, hiding the fact that close protection is not effective. * bpo-30980: Fix double close protection Invalidated self.fd before closing, handling correctly the case when os.close raises. * bpo-30980: Fix fd leak introduced in the fixed test
This commit is contained in:
parent
5b4feb7e86
commit
c648a93ae3
|
@ -619,8 +619,9 @@ if os.name == 'posix':
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.fd < 0:
|
if self.fd < 0:
|
||||||
return
|
return
|
||||||
os.close(self.fd)
|
fd = self.fd
|
||||||
self.fd = -1
|
self.fd = -1
|
||||||
|
os.close(fd)
|
||||||
|
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
return self.fd
|
return self.fd
|
||||||
|
|
|
@ -433,7 +433,10 @@ class FileWrapperTest(unittest.TestCase):
|
||||||
f = asyncore.file_wrapper(fd)
|
f = asyncore.file_wrapper(fd)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
f.close()
|
os.close(f.fd) # file_wrapper dupped fd
|
||||||
|
with self.assertRaises(OSError):
|
||||||
|
f.close()
|
||||||
|
|
||||||
self.assertEqual(f.fd, -1)
|
self.assertEqual(f.fd, -1)
|
||||||
# calling close twice should not fail
|
# calling close twice should not fail
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Reference in New Issue