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

selects.KqueueSelector behaves incorrectly when no fds are registered #73441

Closed
njsmith opened this issue Jan 12, 2017 · 3 comments
Closed

selects.KqueueSelector behaves incorrectly when no fds are registered #73441

njsmith opened this issue Jan 12, 2017 · 3 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir

Comments

@njsmith
Copy link
Contributor

njsmith commented Jan 12, 2017

BPO 29255
Nosy @gvanrossum, @njsmith, @russelldavis
PRs
  • bpo-29255: Wait in KqueueSelector when no fds are registered #19508
  • 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 2020-04-15.18:57:42.078>
    created_at = <Date 2017-01-12.23:35:06.834>
    labels = ['3.7', 'library']
    title = 'selects.KqueueSelector behaves incorrectly when no fds are registered'
    updated_at = <Date 2020-04-15.18:57:42.077>
    user = 'https://github.com/njsmith'

    bugs.python.org fields:

    activity = <Date 2020-04-15.18:57:42.077>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-04-15.18:57:42.078>
    closer = 'gvanrossum'
    components = ['Library (Lib)']
    creation = <Date 2017-01-12.23:35:06.834>
    creator = 'njs'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29255
    keywords = ['patch']
    message_count = 3.0
    messages = ['285352', '366162', '366540']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'njs', 'russelldavis']
    pr_nums = ['19508']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue29255'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @njsmith
    Copy link
    Contributor Author

    njsmith commented Jan 12, 2017

    When calling kevent(), selectors.KqueueSelector.select sets the "maxevents" argument to len(self._fd_to_key). So if there are no fds registered, it passes maxevents=0.

    It turns out that the kevent() API has a special case behavior for maxevents=0: it returns immediately, ignoring timeout. I have no idea why kevent() works this way, but it's specifically called out in the man page:

    The nevents argument determines the size of eventlist. When
    nevents is zero, kevent() will return immediately even if there is a
    timeout specified unlike select(2).

    https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2

    It happens that asyncio doesn't run into this because asyncio always has at least one fd registered with its selector, but this causes problems for other users of the selectors module, e.g.:
    dabeaz/curio#156

    I believe fix would just be to add some code like: "if max_ev == 0: max_ev = 1" to selectors.KqueueSelector.select.

    @njsmith njsmith added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Jan 12, 2017
    @russelldavis
    Copy link
    Mannequin

    russelldavis mannequin commented Apr 10, 2020

    This looks like it's the cause of https://bugs.python.org/issue25680

    @gvanrossum
    Copy link
    Member

    New changeset ba1bcff by Russell Davis in branch 'master':
    bpo-29255: Wait in KqueueSelector.select when no fds are registered (GH-19508)
    ba1bcff

    @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 stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants