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

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

Closed
agronholm mannequin opened this issue Jul 16, 2020 · 7 comments
Closed

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

agronholm mannequin opened this issue Jul 16, 2020 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@agronholm
Copy link
Mannequin

agronholm mannequin commented Jul 16, 2020

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']

    @agronholm
    Copy link
    Mannequin Author

    agronholm mannequin commented Jul 16, 2020

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

    @agronholm agronholm mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error labels Jul 16, 2020
    @agronholm
    Copy link
    Mannequin Author

    agronholm mannequin commented Jul 17, 2020

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

    @1st1
    Copy link
    Member

    1st1 commented Jul 22, 2020

    Alex, do you want to submit a PR?

    @agronholm
    Copy link
    Mannequin Author

    agronholm mannequin commented Jul 22, 2020

    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.

    @agronholm
    Copy link
    Mannequin Author

    agronholm mannequin commented Jul 22, 2020

    Looks like they do – fantastic!

    @1st1
    Copy link
    Member

    1st1 commented Jul 23, 2020

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

    @miss-islington
    Copy link
    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

    @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 topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants