This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: sock_accept() does not remove server socket reader on cancellation
Type: behavior Stage: patch review
Components: asyncio Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex.gronholm, asvetlov, miss-islington, yselivanov
Priority: normal Keywords: patch

Created on 2020-07-16 22:12 by alex.gronholm, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit alex.gronholm, 2020-07-16 22:12 Script to reproduce the error
Pull Requests
URL Status Linked Edit
PR 21595 merged alex.gronholm, 2020-07-22 22:22
PR 21603 merged miss-islington, 2020-07-23 19:45
Messages (7)
msg373777 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2020-07-16 22:12
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).
msg373840 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2020-07-17 17:31
This bug is the same as except for sock_accept().
msg374110 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2020-07-22 21:06
Alex, do you want to submit a PR?
msg374111 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2020-07-22 21:10
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.
msg374112 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2020-07-22 21:21
Looks like they do – fantastic!
msg374145 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2020-07-23 19:45
New changeset 0dd98c2d00a75efbec19c2ed942923981bc06683 by Alex Grönholm in branch 'master':
bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (#21595)
msg374146 - (view) Author: miss-islington (miss-islington) Date: 2020-07-23 20:02
New changeset 4ff8e5ba4fef7f7d0fc1b1872ccb91bc3fd1294d by Miss Islington (bot) in branch '3.9':
bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (GH-21595)
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85489
2020-07-23 20:02:57miss-islingtonsetmessages: + msg374146
2020-07-23 19:45:29miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request20742
2020-07-23 19:45:17yselivanovsetmessages: + msg374145
2020-07-22 22:22:24alex.gronholmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20734
2020-07-22 21:21:15alex.gronholmsetmessages: + msg374112
2020-07-22 21:10:11alex.gronholmsetmessages: + msg374111
2020-07-22 21:06:19yselivanovsetmessages: + msg374110
2020-07-17 17:31:48alex.gronholmsetmessages: + msg373840
2020-07-16 22:12:05alex.gronholmcreate