Skip to content

sock_accept() does not remove server socket reader on cancellation #85489

Description

@agronholm
mannequin
BPO 41317
Nosy @asvetlov, @agronholm, @1st1, @miss-islington
PRs
  • bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() #21595
  • [3.9] bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (GH-21595) #21603
  • Files
  • bug.py: Script to reproduce the error
  • 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 = None
    created_at = <Date 2020-07-16.22:12:05.498>
    labels = ['3.8', 'type-bug', '3.7', '3.9', 'expert-asyncio']
    title = 'sock_accept() does not remove server socket reader on cancellation'
    updated_at = <Date 2020-07-23.20:02:57.073>
    user = 'https://github.com/agronholm'

    bugs.python.org fields:

    activity = <Date 2020-07-23.20:02:57.073>
    actor = 'miss-islington'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2020-07-16.22:12:05.498>
    creator = 'alex.gronholm'
    dependencies = []
    files = ['49319']
    hgrepos = []
    issue_num = 41317
    keywords = ['patch']
    message_count = 7.0
    messages = ['373777', '373840', '374110', '374111', '374112', '374145', '374146']
    nosy_count = 4.0
    nosy_names = ['asvetlov', 'alex.gronholm', 'yselivanov', 'miss-islington']
    pr_nums = ['21595', '21603']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41317'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. agronholm commented on Jul 16, 2020

      agronholmmannequin
      MannequinAuthor

      Unlike with all the other sock_* functions, sock_accept() only removes the reader on the server socket when the socket becomes available for reading (ie. when there's an incoming connection). If the operation is cancelled instead, the reader is not removed.

      If then the server socket is closed and a new socket is created which has the same file number and it is used for a socket operation, it will cause a FileNotFoundError because the event loop thinks it has this fd registered but the epoll object does not agree since all closed sockets are automatically removed from it.

      The attached script reproduces the problem on Fedora Linux 32 (all relevant Python versions), but not on Windows (on any tested Python versions from 3.6 to 3.8).

    2. agronholm commented on Jul 17, 2020

      agronholmmannequin
      MannequinAuthor

      This bug is the same as https://bugs.python.org/issue30064 except for sock_accept().

    3. 1st1 commented on Jul 22, 2020

      @1st1
      Member

      Alex, do you want to submit a PR?

    4. agronholm commented on Jul 22, 2020

      agronholmmannequin
      MannequinAuthor

      Sure, it should be a rather straightforward fix. I have to check if the tests for the related methods test for proper cancellation semantics. It should be even faster if they do.

    5. agronholm commented on Jul 22, 2020

      agronholmmannequin
      MannequinAuthor

      Looks like they do – fantastic!

    6. 1st1 commented on Jul 23, 2020

      @1st1
      Member

      New changeset 0dd98c2 by Alex Grönholm in branch 'master':
      bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (bpo-21595)
      0dd98c2

    7. miss-islington commented on Jul 23, 2020

      @miss-islington
      Contributor

      New changeset 4ff8e5b by Miss Islington (bot) in branch '3.9':
      bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (GH-21595)
      4ff8e5b

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions