Skip to content

Commit 7f52415

Browse files
oranavvstinner
authored andcommitted
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.
1 parent 67a93b3 commit 7f52415

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a bug in :func:`select.select` where, in some cases, the file descriptor
2+
sequences were returned unmodified after a signal interruption, even though the
3+
file descriptors might not be ready yet. :func:`select.select` will now always
4+
return empty lists if a timeout has occurred. Patch by Oran Avraham.

Modules/selectmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
335335
if (tvp) {
336336
timeout = deadline - _PyTime_GetMonotonicClock();
337337
if (timeout < 0) {
338+
/* bpo-35310: lists were unmodified -- clear them explicitly */
339+
FD_ZERO(&ifdset);
340+
FD_ZERO(&ofdset);
341+
FD_ZERO(&efdset);
338342
n = 0;
339343
break;
340344
}

0 commit comments

Comments
 (0)