From 76ad1e94b6320584a75579e8d8fce4642abb0b5a Mon Sep 17 00:00:00 2001 From: oranav Date: Mon, 3 Dec 2018 22:42:26 +0200 Subject: [PATCH] bpo-35310: Clear select() lists before returning upon EINTR select() calls are retried on EINTR (per PEP 475). However, if a timeout was provided and the deadline has passed after running the signal handlers, we should clear rlist, wlist and xlist since select(2) left them unmodified. --- .../next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst | 4 ++++ Modules/selectmodule.c | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst diff --git a/Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst b/Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst new file mode 100644 index 00000000000000..1ab2e168c86a27 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-12-03-19-45-00.bpo-35310.9k28gR.rst @@ -0,0 +1,4 @@ +Fix a bug in :func:`select.select` where, in some cases, the file descriptor +sequences were returned unmodified after a signal interruption, even though the +file descriptors might not be ready yet. :func:`select.select` will now always +return empty lists if a timeout has occurred. Patch by Oran Avraham. diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 5a6b13466c8061..fe69cd58dc6a28 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -335,6 +335,10 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist, if (tvp) { timeout = deadline - _PyTime_GetMonotonicClock(); if (timeout < 0) { + /* bpo-35310: lists were unmodified -- clear them explicitly */ + FD_ZERO(&ifdset); + FD_ZERO(&ofdset); + FD_ZERO(&efdset); n = 0; break; }