bpo-33263: Fix FD leak in _SelectorSocketTransport (GH-6450)

* bpo-33263 Fix FD leak in _SelectorSocketTransport. (GH-6450)

Under particular circumstances _SelectorSocketTransport can try to add a reader
even the transport is already being closed. This can lead to FD leak and
invalid stated of the following connections. Fixed the SelectorSocketTransport
to add the reader only if the trasport is still active.
This commit is contained in:
Vlad Starostin 2018-05-21 11:13:45 +03:00 committed by Andrew Svetlov
parent 4054b172ab
commit a84d0b361a
3 changed files with 25 additions and 3 deletions

View file

@ -871,6 +871,21 @@ class SelectorTransportTests(test_utils.TestCase):
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
def test__add_reader(self):
tr = self.create_transport()
tr._buffer.extend(b'1')
tr._add_reader(7, mock.sentinel)
self.assertTrue(self.loop.readers)
tr._force_close(None)
self.assertTrue(tr.is_closing())
self.assertFalse(self.loop.readers)
# can not add readers after closing
tr._add_reader(7, mock.sentinel)
self.assertFalse(self.loop.readers)
class SelectorSocketTransportTests(test_utils.TestCase):