This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: select which was interrupted by EINTR isn't re-run if the timeout has passed
Type: behavior Stage: resolved
Components: Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Brian Maissy, miss-islington, oranav, vstinner
Priority: normal Keywords: patch

Created on 2018-11-25 13:19 by Brian Maissy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
select_eintr.py Brian Maissy, 2018-11-25 13:19
Pull Requests
URL Status Linked Edit
PR 10700 closed oranav, 2018-11-25 14:46
PR 10877 merged oranav, 2018-12-03 20:53
PR 10948 merged miss-islington, 2018-12-05 20:36
PR 10949 merged miss-islington, 2018-12-05 20:36
Messages (10)
msg330388 - (view) Author: Brian Maissy (Brian Maissy) Date: 2018-11-25 13:19
If a call to select.select() was interrupted by a signal and the select syscall set an errno of EINTR, then under PEP 475 the select call should be re-executed.

If, however, there is a signal handler which takes enough time that the select's timeout expires, select() is not retried, and the rlist is returned as-is (with fds in it which are not ready for reading).

Under this condition, either select() should be re-run with a timeout of 0, or the fd lists should be emptied before returning.

Example code which reproduces the problem attached.
msg330389 - (view) Author: Brian Maissy (Brian Maissy) Date: 2018-11-25 13:22
I believe the offending line in the source is this break statement:
https://github.com/python/cpython/blob/master/Modules/selectmodule.c#L339
msg330464 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-26 21:17
> Under this condition, either select() should be re-run with a timeout of 0, or the fd lists should be emptied before returning.

What is the current behavior?

Are you trying to fix a bug?
msg330493 - (view) Author: Brian Maissy (Brian Maissy) Date: 2018-11-27 07:07
The current behavior is:

> select() is not retried, and the rlist is returned as-is (with fds in it which are not ready for reading)

Yes, this is a bug. It results in select() indicating that fd are ready for reading when they, in fact, are not.
msg330504 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-27 11:02
Ah! I missed attached select_eintr.py script. Ok, I reproduced the bug and I agree that it must be fixed.
msg331158 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-05 20:36
New changeset 7f52415a6d4841d77d3b7853e83b25a22e0048dc by Victor Stinner (Oran Avraham) in branch 'master':
bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
https://github.com/python/cpython/commit/7f52415a6d4841d77d3b7853e83b25a22e0048dc
msg331161 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-05 20:38
Python 2.7 is not affected: select() isn't retried if it fails with EINTR.
msg331172 - (view) Author: miss-islington (miss-islington) Date: 2018-12-05 21:29
New changeset b2e0649dd9a36d54478d0edb623a18d7379e6f19 by Miss Islington (bot) in branch '3.6':
bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
https://github.com/python/cpython/commit/b2e0649dd9a36d54478d0edb623a18d7379e6f19
msg331173 - (view) Author: miss-islington (miss-islington) Date: 2018-12-05 21:31
New changeset 34510781901b75c9aeca79db41ce0fa92c67878f by Miss Islington (bot) in branch '3.7':
bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
https://github.com/python/cpython/commit/34510781901b75c9aeca79db41ce0fa92c67878f
msg331191 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-05 23:17
Ok, the bug should now be fixed in 3.6, 3.7 and master branches.

Thanks Brian Maissy for the bug report and thanks Oran Avraham for the fix!

I hope that we will understand why I didn't want to add a new functional test ;-)
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79491
2018-12-05 23:17:30vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg331191

stage: patch review -> resolved
2018-12-05 21:31:10miss-islingtonsetmessages: + msg331173
2018-12-05 21:29:10miss-islingtonsetnosy: + miss-islington
messages: + msg331172
2018-12-05 20:38:04vstinnersetmessages: + msg331161
2018-12-05 20:36:45miss-islingtonsetpull_requests: + pull_request10199
2018-12-05 20:36:32miss-islingtonsetpull_requests: + pull_request10198
2018-12-05 20:36:06vstinnersetmessages: + msg331158
2018-12-03 20:53:13oranavsetpull_requests: + pull_request10116
2018-11-27 11:02:10vstinnersetmessages: + msg330504
versions: - Python 3.5
2018-11-27 07:08:40Brian Maissysetnosy: + oranav
2018-11-27 07:07:29Brian Maissysetmessages: + msg330493
2018-11-26 21:17:36vstinnersetnosy: + vstinner
messages: + msg330464
2018-11-25 14:46:24oranavsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9951
2018-11-25 13:22:50Brian Maissysetmessages: + msg330389
2018-11-25 13:19:06Brian Maissycreate