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
The Tribler codebase could be affected by this bug:
If you have ever used asyncio.create_task you may have created a bug for yourself that is challenging (read almost impossible) to reproduce. If it occurs, your code will likely fail in unpredictable ways.
The root cause of this Heisenbug is that if you don't hold a reference to the task object returned by create_task then the task may disappear without warning when Python runs garbage collection. In other words, the code in your task will stop running with no obvious indication why.
I think the asyncio usage of weak references is a bug (that probably would not be fixed). The correct behavior for the loop is to become the task owner until the task is done.
In the source code, when a task is created, it is immediately registered as ready in an internal running loop structure - that is a hard reference - when the loop cycles through on iteration and fails to call any task there, this hard reference is dropped. That this "dropping" is not deterministic maybe is a bug that could be fixed.
And the example that reproduces the bug is provided with the following comment
For anecdote, I experimented around, and the results are really nasty with random task-drops starting at around 2500 concurrent tasks with this code. Including an await asyncio.sleep(0) in the loop where the tasks are created makes it all run flawlessly up to millions of tasks.
If our current fix with AsyncGroup turns out to be insufficient, maybe we can also add some generic workaround with something like await asyncio.sleep(0) added to the right place.
The Tribler codebase could be affected by this bug:
https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/
The text was updated successfully, but these errors were encountered: