From 02ab3fc4b5b82b832788382ff4c68ee8b75b33ef Mon Sep 17 00:00:00 2001 From: MartinAltmayer Date: Tue, 31 Jul 2018 15:06:12 +0100 Subject: [PATCH 1/2] bpo-34263 Cap timeout submitted to epoll/select etc. to one day. (GH-8532) (cherry picked from commit 944451cd8d3e897138f4b43569de13cd081ee251) Co-authored-by: MartinAltmayer --- Doc/library/asyncio-eventloop.rst | 4 ---- Lib/asyncio/base_events.py | 5 ++++- .../next/Library/2018-07-28-17-00-36.bpo-34263.zUfRsu.rst | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-07-28-17-00-36.bpo-34263.zUfRsu.rst diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index bdba9962df6227..cfcab1730c6ba7 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -161,10 +161,6 @@ Which clock is used depends on the (platform-specific) event loop implementation; ideally it is a monotonic clock. This will generally be a different clock than :func:`time.time`. -.. note:: - - Timeouts (relative *delay* or absolute *when*) should not exceed one day. - .. method:: AbstractEventLoop.call_later(delay, callback, *args) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 79f0d63c5726e8..30ac5924d06bd4 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -56,6 +56,9 @@ _HAS_IPv6 = hasattr(socket, 'AF_INET6') +# Maximum timeout passed to select to avoid OS limitations +MAXIMUM_SELECT_TIMEOUT = 24 * 3600 + def _format_handle(handle): cb = handle._callback @@ -1378,7 +1381,7 @@ def _run_once(self): elif self._scheduled: # Compute the desired timeout. when = self._scheduled[0]._when - timeout = max(0, when - self.time()) + timeout = min(max(0, when - self.time()), MAXIMUM_SELECT_TIMEOUT) if self._debug and timeout != 0: t0 = self.time() diff --git a/Misc/NEWS.d/next/Library/2018-07-28-17-00-36.bpo-34263.zUfRsu.rst b/Misc/NEWS.d/next/Library/2018-07-28-17-00-36.bpo-34263.zUfRsu.rst new file mode 100644 index 00000000000000..799463b5916350 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-07-28-17-00-36.bpo-34263.zUfRsu.rst @@ -0,0 +1,2 @@ +asyncio's event loop will not pass timeouts longer than one day to +epoll/select etc. From b1ae8ae09775837361c34cfcc3a2f3408742f4cb Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 31 Jul 2018 10:09:56 -0400 Subject: [PATCH 2/2] Update asyncio-eventloop.rst --- Doc/library/asyncio-eventloop.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index cfcab1730c6ba7..bdba9962df6227 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -161,6 +161,10 @@ Which clock is used depends on the (platform-specific) event loop implementation; ideally it is a monotonic clock. This will generally be a different clock than :func:`time.time`. +.. note:: + + Timeouts (relative *delay* or absolute *when*) should not exceed one day. + .. method:: AbstractEventLoop.call_later(delay, callback, *args)