Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select which was interrupted by EINTR isn't re-run if the timeout has passed #79491

Closed
BrianMaissy mannequin opened this issue Nov 25, 2018 · 10 comments
Closed

select which was interrupted by EINTR isn't re-run if the timeout has passed #79491

BrianMaissy mannequin opened this issue Nov 25, 2018 · 10 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@BrianMaissy
Copy link
Mannequin

BrianMaissy mannequin commented Nov 25, 2018

BPO 35310
Nosy @vstinner, @miss-islington, @oranav
PRs
  • bpo-35310: Retry select() calls on EINTR even if deadline has passed #10700
  • bpo-35310: Clear select() lists before returning upon EINTR #10877
  • [3.6] bpo-35310: Clear select() lists before returning upon EINTR (GH-10877) #10948
  • [3.7] bpo-35310: Clear select() lists before returning upon EINTR (GH-10877) #10949
  • Files
  • select_eintr.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-12-05.23:17:30.083>
    created_at = <Date 2018-11-25.13:19:06.435>
    labels = ['3.8', 'type-bug', '3.7']
    title = "select which was interrupted by EINTR isn't re-run if the timeout has passed"
    updated_at = <Date 2018-12-05.23:17:30.082>
    user = 'https://bugs.python.org/BrianMaissy'

    bugs.python.org fields:

    activity = <Date 2018-12-05.23:17:30.082>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-05.23:17:30.083>
    closer = 'vstinner'
    components = []
    creation = <Date 2018-11-25.13:19:06.435>
    creator = 'Brian Maissy'
    dependencies = []
    files = ['47945']
    hgrepos = []
    issue_num = 35310
    keywords = ['patch']
    message_count = 10.0
    messages = ['330388', '330389', '330464', '330493', '330504', '331158', '331161', '331172', '331173', '331191']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'miss-islington', 'Brian Maissy', 'oranav']
    pr_nums = ['10700', '10877', '10948', '10949']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35310'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @BrianMaissy
    Copy link
    Mannequin Author

    BrianMaissy mannequin commented Nov 25, 2018

    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.

    @BrianMaissy BrianMaissy mannequin added 3.7 (EOL) end of life 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels Nov 25, 2018
    @BrianMaissy
    Copy link
    Mannequin Author

    BrianMaissy mannequin commented Nov 25, 2018

    I believe the offending line in the source is this break statement:
    https://github.com/python/cpython/blob/master/Modules/selectmodule.c#L339

    @vstinner
    Copy link
    Member

    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?

    @BrianMaissy
    Copy link
    Mannequin Author

    BrianMaissy mannequin commented Nov 27, 2018

    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.

    @vstinner
    Copy link
    Member

    Ah! I missed attached select_eintr.py script. Ok, I reproduced the bug and I agree that it must be fixed.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2018

    New changeset 7f52415 by Victor Stinner (Oran Avraham) in branch 'master':
    bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
    7f52415

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2018

    Python 2.7 is not affected: select() isn't retried if it fails with EINTR.

    @miss-islington
    Copy link
    Contributor

    New changeset b2e0649 by Miss Islington (bot) in branch '3.6':
    bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
    b2e0649

    @miss-islington
    Copy link
    Contributor

    New changeset 3451078 by Miss Islington (bot) in branch '3.7':
    bpo-35310: Clear select() lists before returning upon EINTR (GH-10877)
    3451078

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2018

    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 ;-)

    @vstinner vstinner closed this as completed Dec 5, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants