diff options
author | Vlad Starostin <drtyrsa@yandex.ru> | 2018-05-21 08:13:45 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2018-05-21 08:13:45 (GMT) |
commit | a84d0b361a26c05c6fadc6640591ec3feee5bfb5 (patch) | |
tree | fb5b5ad67a0122a5094af74d0b5ff43a6c768ca9 /Lib/asyncio | |
parent | 4054b172ab59054715a2aaf4979bd84ac23e3ada (diff) | |
download | cpython-a84d0b361a26c05c6fadc6640591ec3feee5bfb5.zip cpython-a84d0b361a26c05c6fadc6640591ec3feee5bfb5.tar.gz cpython-a84d0b361a26c05c6fadc6640591ec3feee5bfb5.tar.bz2 |
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.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/selector_events.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 354bf9d..f9533a1 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -706,6 +706,12 @@ class _SelectorTransport(transports._FlowControlMixin, def get_write_buffer_size(self): return len(self._buffer) + def _add_reader(self, fd, callback, *args): + if self._closing: + return + + self._loop._add_reader(fd, callback, *args) + class _SelectorSocketTransport(_SelectorTransport): @@ -732,7 +738,7 @@ class _SelectorSocketTransport(_SelectorTransport): self._loop.call_soon(self._protocol.connection_made, self) # only start reading when connection_made() has been called - self._loop.call_soon(self._loop._add_reader, + self._loop.call_soon(self._add_reader, self._sock_fd, self._read_ready) if waiter is not None: # only wake up the waiter when connection_made() has been called @@ -754,7 +760,7 @@ class _SelectorSocketTransport(_SelectorTransport): if self._closing or not self._paused: return self._paused = False - self._loop._add_reader(self._sock_fd, self._read_ready) + self._add_reader(self._sock_fd, self._read_ready) if self._loop.get_debug(): logger.debug("%r resumes reading", self) @@ -930,7 +936,7 @@ class _SelectorDatagramTransport(_SelectorTransport): self._address = address self._loop.call_soon(self._protocol.connection_made, self) # only start reading when connection_made() has been called - self._loop.call_soon(self._loop._add_reader, + self._loop.call_soon(self._add_reader, self._sock_fd, self._read_ready) if waiter is not None: # only wake up the waiter when connection_made() has been called |