]> granicus.if.org Git - python/commitdiff
[2.7] bpo-31334: Fix timeout in select.poll.poll() (GH-3277) (#4034)
authorRiccardo Coccioli <volans-@users.noreply.github.com>
Wed, 18 Oct 2017 12:04:04 +0000 (14:04 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 18 Oct 2017 12:04:04 +0000 (15:04 +0300)
Always pass -1, or INFTIM where defined, to the poll() system call when
a negative timeout is passed to the poll.poll([timeout]) method in the
select module. Various OSes throw an error with arbitrary negative
values..
(cherry picked from commit 6cfa927ceb931ad968b5b03e4a2bffb64a8a0604)

Lib/test/test_poll.py
Misc/ACKS
Misc/NEWS.d/next/Library/2017-09-04-00-22-31.bpo-31334.9WYRfi.rst [new file with mode: 0644]
Modules/selectmodule.c

index 14dbfcf47b24183a2d084d14f8e22fbba874849a..7ad693d319fb9cb70510278b69b0013ecc538529 100644 (file)
@@ -208,7 +208,7 @@ class PollTests(unittest.TestCase):
     @unittest.skipUnless(threading, 'Threading required for this test.')
     @reap_threads
     def test_poll_blocks_with_negative_ms(self):
-        for timeout_ms in [None, -1, -1.0]:
+        for timeout_ms in [None, -1000, -1, -1.0]:
             # Create two file descriptors. This will be used to unlock
             # the blocking call to poll.poll inside the thread
             r, w = os.pipe()
index 688cd470d20436452d969c3cefd3fdac38d8d44b..e076c32b14d1dcbe12a4c2f6bf03c98edebb403e 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -262,6 +262,7 @@ Brad Clements
 Robbie Clemons
 Steve Clift
 HervĂ© Coatanhay
+Riccardo Coccioli
 Nick Coghlan
 Josh Cogliati
 Dave Cole
diff --git a/Misc/NEWS.d/next/Library/2017-09-04-00-22-31.bpo-31334.9WYRfi.rst b/Misc/NEWS.d/next/Library/2017-09-04-00-22-31.bpo-31334.9WYRfi.rst
new file mode 100644 (file)
index 0000000..1cbfd25
--- /dev/null
@@ -0,0 +1,3 @@
+Fix ``poll.poll([timeout])`` in the ``select`` module for arbitrary negative
+timeouts on all OSes where it can only be a non-negative integer or -1.
+Patch by Riccardo Coccioli.
index a38aa08798cc3def4557c2d840add9bb4273f51c..ce4c15b6946a74a3f888598553fcc7229f5b833d 100644 (file)
@@ -530,6 +530,17 @@ poll_poll(pollObject *self, PyObject *args)
             return NULL;
     }
 
+    /* On some OSes, typically BSD-based ones, the timeout parameter of the
+       poll() syscall, when negative, must be exactly INFTIM, where defined,
+       or -1. See issue 31334. */
+    if (timeout < 0) {
+#ifdef INFTIM
+        timeout = INFTIM;
+#else
+        timeout = -1;
+#endif
+    }
+
     /* Avoid concurrent poll() invocation, issue 8865 */
     if (self->poll_running) {
         PyErr_SetString(PyExc_RuntimeError,