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

[FreeBSD, OSX] Socket module: incorrect usage of poll(2) #81992

Closed
akhramov mannequin opened this issue Aug 10, 2019 · 8 comments
Closed

[FreeBSD, OSX] Socket module: incorrect usage of poll(2) #81992

akhramov mannequin opened this issue Aug 10, 2019 · 8 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes OS-mac stdlib Python modules in the Lib dir topic-IO

Comments

@akhramov
Copy link
Mannequin

akhramov mannequin commented Aug 10, 2019

BPO 37811
Nosy @ronaldoussoren, @vstinner, @ned-deily, @koobs, @miss-islington, @shihai1991, @akhramov
PRs
  • bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module #15202
  • [3.7] bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202) #15289
  • [3.8] bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202) #15290
  • Files
  • connect_eintr.py: Repro
  • 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 2019-08-14.22:38:37.325>
    created_at = <Date 2019-08-10.20:29:31.173>
    labels = ['OS-mac', '3.8', '3.9', 'expert-IO', '3.7', 'library']
    title = '[FreeBSD, OSX] Socket module: incorrect usage of poll(2)'
    updated_at = <Date 2019-08-14.22:38:37.322>
    user = 'https://github.com/akhramov'

    bugs.python.org fields:

    activity = <Date 2019-08-14.22:38:37.322>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-08-14.22:38:37.325>
    closer = 'vstinner'
    components = ['Library (Lib)', 'macOS', 'IO', 'FreeBSD']
    creation = <Date 2019-08-10.20:29:31.173>
    creator = 'akhramov'
    dependencies = []
    files = ['48537']
    hgrepos = []
    issue_num = 37811
    keywords = ['patch']
    message_count = 8.0
    messages = ['349356', '349382', '349383', '349753', '349754', '349760', '349761', '349772']
    nosy_count = 7.0
    nosy_names = ['ronaldoussoren', 'vstinner', 'ned.deily', 'koobs', 'miss-islington', 'shihai1991', 'akhramov']
    pr_nums = ['15202', '15289', '15290']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37811'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @akhramov
    Copy link
    Mannequin Author

    akhramov mannequin commented Aug 10, 2019

    FreeBSD implementation of poll(2) restricts timeout argument to be either zero, or positive, or equal to INFTIM (-1).

    Unless otherwise overridden, socket timeout defaults to -1. This value is then converted to milliseconds (-1000) and used as argument to the poll syscall.

    poll returns EINVAL (22), and the connection fails.

    I have discovered this bug during the EINTR handling testing, and have naturally found a repro code in https://bugs.python.org/issue23618 (see connect_eintr.py, attached). On GNU/Linux, the example runs as expected.

    @akhramov akhramov mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Aug 10, 2019
    @shihai1991
    Copy link
    Member

    I found an OS distinguishing behavior in https://github.com/python/cpython/blob/master/Modules/selectmodule.c#L603-L612

    @koobs
    Copy link

    koobs commented Aug 11, 2019

    See Also: bpo-31334

    @akhramov akhramov mannequin added stdlib Python modules in the Lib dir OS-mac topic-IO labels Aug 14, 2019
    @vstinner
    Copy link
    Member

    See Also: bpo-31334

    Oh, I didn't know bpo-31334. This issue is basically a duplicate of bpo-31334, but triggered differently.

    @vstinner
    Copy link
    Member

    New changeset 2814620 by Victor Stinner (Artem Khramov) in branch 'master':
    bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
    2814620

    @miss-islington
    Copy link
    Contributor

    New changeset 123f6c4 by Miss Islington (bot) in branch '3.8':
    bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
    123f6c4

    @miss-islington
    Copy link
    Contributor

    New changeset b0b178a by Miss Islington (bot) in branch '3.7':
    bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
    b0b178a

    @vstinner
    Copy link
    Member

    Thanks Artem Khramov for the nice analysis of the root issue! And thanks for the fix! The bug is now fixed in 3.7, 3.8 and master branches.

    Python 2.7 is not affected: I added sock_call_ex() helper function in Python 3 when I implemeneted the PEP-475 (Retry system calls failing with EINTR).

    @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 3.9 only security fixes OS-mac stdlib Python modules in the Lib dir topic-IO
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants