Sitelet https://github.com/python/cpython/issues/120974
Skip to content

asyncio thread-safety issues in the free-threaded build #120974

Description

@colesbury

Bug report

  1. fi_freelist isn't thread-safe (move to pycore_freelist.h and follow that pattern)
  2. enter_task, leave_task, and swap_current_task aren't thread-safe due to shared state->current_tasks and borrowed references.
  3. register_task and unregister_task aren't thread-safe due to shared state->asyncio_tasks linked list
  4. _asyncio_all_tasks_impl isn't thread-safe due the the asyncio_tasks linked list.

For 2, 3, and 4, we can consider using critical sections to protect the accesses to state->current_tasks and state->asyncio_tasks.

Longer term, moving data to per-loop will probably help with multi-threaded scaling.

Linked PRs

Activity

  1. kumaraditya303 commented on Jun 25, 2024

    @kumaraditya303
    Contributor

    I think that the pure Python fallback isn't thread safe either, FWIW I think there are more thread safety issues than these, asyncio code was written with assumption of GIL.

  2. corona10 commented on Jun 25, 2024

    @corona10
    Member

    asyncio code was written with assumption of GIL.

    Yeah, but for landing PEP 703, we are trying to change modules, not depending on the GIL, even if we need to re-write some parts of the implementation with a conditional flag. (If the new written part requires some performance overhead)

  3. added 3 commits that reference this issue on Jul 22, 2024
  4. added a commit that references this issue on Jul 23, 2024
  5. added a commit that references this issue on Jul 23, 2024
  6. added a commit that references this issue on Jul 23, 2024
  7. 6 remaining items

  8. added 4 commits that reference this issue on Jul 24, 2024
  9. added 2 commits that reference this issue on Jul 26, 2024
  10. added a commit that references this issue on Aug 2, 2024
  11. added a commit that references this issue on Aug 2, 2024
  12. added a commit that references this issue on Aug 2, 2024
  13. added a commit that references this issue on Aug 7, 2024
  14. added a commit that references this issue on Aug 11, 2024
  15. moved this from Todo to Done in asyncioon Aug 11, 2024
  16. added 2 commits that reference this issue on Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions