[issue42130] AsyncIO's wait_for can hide cancellation in a rare race condition

2021-05-13 Thread Adam Liddell


Change by Adam Liddell :


--
nosy: +aaliddell

___
Python tracker 
<https://bugs.python.org/issue42130>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37658] In some cases asyncio.wait_for can lead to socket leak.

2021-05-13 Thread Adam Liddell


Adam Liddell  added the comment:

Some discussion leading up to that change is here 
https://github.com/MagicStack/asyncpg/pull/548 and in the issues it links.

--

___
Python tracker 
<https://bugs.python.org/issue37658>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37658] In some cases asyncio.wait_for can lead to socket leak.

2021-05-13 Thread Adam Liddell


Adam Liddell  added the comment:

Wrapping every resource allocating call like that is what we were trying to 
avoid, since it makes wait_for go from a simple one-line helper to something 
you have to be very careful with.

Conceptually, a user should expect that wait_for should behave the exact same 
as awaiting the underlying awaitable, just with auto-cancellation. The problem 
with the current wait_for is that there is a gap where the underlying task may 
have completed but a cancellation arrives. In this case, we need to raise the 
cancellation to be a good asyncio citizen, but the underlying task has no 
opportunity to act on the cancellation (to free the resource) since it is 
already complete and cannot be re-entered. So the resource returned by the 
completed task gets stuck in limbo, since we can't return it and we can't 
assume a generic 'close' behaviour.

See my comment in the PR for a suggestion about an alternative structure for 
wait_for, which may avoid this gap and hence prevent the leak (but I have not 
tested it!)

--

___
Python tracker 
<https://bugs.python.org/issue37658>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com