You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sock_accept() does not remove server socket reader on cancellation #85489
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=Noneclosed_at=Nonecreated_at=<Date2020-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=<Date2020-07-23.20:02:57.073>user='https://github.com/agronholm'
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).
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.
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
Activity
agronholm commentedon 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 commentedon Jul 17, 2020
This bug is the same as https://bugs.python.org/issue30064 except for sock_accept().
1st1 commentedon Jul 22, 2020
Alex, do you want to submit a PR?
agronholm commentedon 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 commentedon Jul 22, 2020
Looks like they do – fantastic!
1st1 commentedon 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 commentedon Jul 23, 2020
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