summaryrefslogtreecommitdiffstats
path: root/Lib/selectors.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-09-15 23:30:42 (GMT)
committerYury Selivanov <yury@magic.io>2016-09-15 23:30:42 (GMT)
commit525aedc5fae90e5195adb2d34ec33f1a773540fc (patch)
tree80298262b1fcc7e93cf76035e354535b89af2b8d /Lib/selectors.py
parentd6c6771fc9682713ff2ebae2cd02ddbd2b48f657 (diff)
downloadcpython-525aedc5fae90e5195adb2d34ec33f1a773540fc.zip
cpython-525aedc5fae90e5195adb2d34ec33f1a773540fc.tar.gz
cpython-525aedc5fae90e5195adb2d34ec33f1a773540fc.tar.bz2
Issue #27759: Fix selectors incorrectly retain invalid file descriptors.
Patch by Mark Williams.
Diffstat (limited to 'Lib/selectors.py')
-rw-r--r--Lib/selectors.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index d8769e3..89680a2 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -408,7 +408,11 @@ if hasattr(select, 'epoll'):
epoll_events |= select.EPOLLIN
if events & EVENT_WRITE:
epoll_events |= select.EPOLLOUT
- self._epoll.register(key.fd, epoll_events)
+ try:
+ self._epoll.register(key.fd, epoll_events)
+ except BaseException:
+ super().unregister(fileobj)
+ raise
return key
def unregister(self, fileobj):
@@ -530,14 +534,18 @@ if hasattr(select, 'kqueue'):
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
- if events & EVENT_READ:
- kev = select.kevent(key.fd, select.KQ_FILTER_READ,
- select.KQ_EV_ADD)
- self._kqueue.control([kev], 0, 0)
- if events & EVENT_WRITE:
- kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
- select.KQ_EV_ADD)
- self._kqueue.control([kev], 0, 0)
+ try:
+ if events & EVENT_READ:
+ kev = select.kevent(key.fd, select.KQ_FILTER_READ,
+ select.KQ_EV_ADD)
+ self._kqueue.control([kev], 0, 0)
+ if events & EVENT_WRITE:
+ kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
+ select.KQ_EV_ADD)
+ self._kqueue.control([kev], 0, 0)
+ except BaseException:
+ super().unregister(fileobj)
+ raise
return key
def unregister(self, fileobj):