async-timeout icon indicating copy to clipboard operation
async-timeout copied to clipboard

Fix race conditions, support Python 3.11

Open asvetlov opened this issue 3 years ago • 6 comments
trafficstars

asvetlov avatar Feb 17 '22 13:02 asvetlov

Python 3.11 tests fail, not released yet Python 3.11.0a6+ required

asvetlov avatar Feb 17 '22 14:02 asvetlov

If this fixes the same race conditions we were looking at before, can you put the tests back in from that discussion? Seems you reverted them for some reason: https://github.com/aio-libs/async-timeout/commit/ab04eb53dcf49388b6e6eacf0a50bafe19c5c74b

Dreamsorcerer avatar Feb 17 '22 21:02 Dreamsorcerer

Thanks, I lost these tests. Not sure if 1ms delay produces stable CI. Let me port tests and see how they work

asvetlov avatar Feb 18 '22 09:02 asvetlov

Thanks, I lost these tests. Not sure if 1ms delay produces stable CI. Let me port tests and see how they work

It worked 100% of the times we tried it so far. If the last assert for call_order fails, then the timing went wrong. If it fails anywhere else, then the race condition is not fixed.

Dreamsorcerer avatar Feb 18 '22 17:02 Dreamsorcerer

I think this will still fail the second test. If the timeout cancellation is followed by the explicit cancellation, then the explicit cancellation is ignored. Without fixing this, it would require a user to do something awkward everytime they cancel a task, like:

while not task.cancel():
    await asyncio.sleep(0)

I think we'll still need https://bugs.python.org/issue45098 With the new ExceptionGroup, I think my suggestion should change to raising multiple CancelledErrors. Then we can replace the timeout CancelledError with a TimeoutError and reraise any other CancelledErrors.

Dreamsorcerer avatar Feb 18 '22 19:02 Dreamsorcerer

@Dreamsorcerer you may be interested in CPython discussion about asyncio timeouts design: https://bugs.python.org/issue46771?@ok_message=msg%20413603%20created%0Aissue%2046771%20message_count%2C%20messages%20edited%20ok&@template=item

Please feel free to join us. I suggest suspending asyncio-timeout upgrading until the asyncio timeout has landed.

asvetlov avatar Feb 20 '22 19:02 asvetlov