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

nmatravolgyi report at bugs.python.org
Sun May 9 16:15:37 EDT 2021


nmatravolgyi <nandor.matra at gmail.com> added the comment:

I've also found this deficiency of asyncio.wait_for by debugging an obscure hang in an application. Back then I've quickly made an issue about it: https://bugs.python.org/issue43389

I've just closed it as duplicate, since this issue covers the same bug and has been around longer.

I'm surprised this issue has not got more attention. This definitely needs a fix. Ignoring a CancellationError is something that is heavily discouraged by the documentation in general. Silently ignoring/eating a cancellation makes this construct unreliable without good workarounds, aside from not using it.

For a specific application, this was so broken, that I had to come up with a fix in the short term. I made an asyncio.wait_for variant available as a library that fixes the problem: https://github.com/Traktormaster/wait-for2

The repository has a detailed description of the issue and the way it fixes it. It also has test cases to assert the behaviour of the builtin and the fixed wait_for construct from the library.

----------
nosy: +nmatravolgyi

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42130>
_______________________________________


More information about the Python-bugs-list mailing list