GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `KqueueSelector` miscounts max events · Issue #110038 · python/cpython

KqueueSelector miscounts max events #110038

New issue
Copy link
New issue
Copy link
Closed
Closed
KqueueSelector miscounts max events#110038
Copy link
Labels
OS-freebsdtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sorcio
sorcio
opened on Sep 28, 2023
Issue body actions

Bug report

Bug description:

KqueueSelector.select() may not get all events if a fd is registered for both read and write.

kqueue requires to register two filters, one for read and one for write. But KqueueSelector.select() calls kqueue.control() counting the number of registered fds, not the filters. As a result a single call to select() won't return all the available events.

>>> import socket, selectors
>>> sel = selectors.KqueueSelector()
>>> s1, s2 = socket.socketpair()
>>> sel.register(s1, selectors.EVENT_READ | selectors.EVENT_WRITE)
SelectorKey(fileobj=<socket.socket fd=4, family=1, type=1, proto=0>, fd=4, events=3, data=None)
>>> s2.send(b"foo")
3
>>> sel.select()
[(SelectorKey(fileobj=<socket.socket fd=4, family=1, type=1, proto=0>, fd=4, events=3, data=None), 2)]
>>> sel.select()
[(SelectorKey(fileobj=<socket.socket fd=4, family=1, type=1, proto=0>, fd=4, events=3, data=None), 1)]

(Note that the two events are only visible on two subsequent selects)

For users like asyncio, this might mean missing a loop cycle or more (depending on number of registered readers/writers and ready events) before an event is seen. I previously said that this might cause deadlocks but I could not produce an example where a read/write event is never seen.

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

macOS, Other

Linked PRs

  • gh-110038: KqueueSelector must count all read/write events #110039
  • [3.12] gh-110038: KqueueSelector must count all read/write events (GH-110039) #110043
  • [3.11] gh-110038: KqueueSelector must count all read/write events (GH-110039) #110044

Activity

  1. sorcio
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 28, 2023
  2. sorcio
    added a commit that references this issue on Sep 28, 2023

    pythongh-110038: KqueueSelector must count all read/write events

    44980b7
  3. vstinner
    added a commit that references this issue on Sep 28, 2023

    gh-110038: KqueueSelector must count all read/write events (#110039)

    b14f0ab
  4. sorcio
    added 2 commits that reference this issue on Sep 28, 2023

    [3.12] pythongh-110038: KqueueSelector must count all read/write even…

    5012cf7

    [3.11] pythongh-110038: KqueueSelector must count all read/write even…

    01b23d0
  5. vstinner
    added a commit that references this issue on Sep 28, 2023

    [3.11] gh-110038: KqueueSelector must count all read/write events (GH…

    d6e8001
  6. csm10495
    added a commit that references this issue on Sep 29, 2023

    pythongh-110038: KqueueSelector must count all read/write events (pyt…

    eb292de
  7. vstinner
    added
    OS-freebsd
    on Oct 1, 2023
  8. Yhg1s
    added a commit that references this issue on Oct 2, 2023

    [3.12] gh-110038: KqueueSelector must count all read/write events (GH…

    c794103
  9. hugovk commented on Nov 9, 2023

    @hugovk
    hugovk
    on Nov 9, 2023
    Member
    More actions

    Thanks for the issue and PRs!

  10. hugovk
    closed this as completedon Nov 9, 2023
  11. vstinner commented on Nov 9, 2023

    @vstinner
    vstinner
    on Nov 9, 2023
    Member
    More actions

    Thanks for the fix @sorcio.

  12. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-110038: KqueueSelector must count all read/write events (pyt…

    4b73ee7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-freebsdtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.