bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)

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, rlist, wlist and xlist should be cleared since select(2)
left them unmodified.
(cherry picked from commit 7f52415a6d)

Co-authored-by: Oran Avraham <252748+oranav@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2018-12-05 13:31:07 -08:00 committed by GitHub
parent ac8b47c8b4
commit 3451078190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -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.

View File

@ -279,6 +279,10 @@ select_select(PyObject *self, PyObject *args)
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;
}