Skip to content

data race with extension modules checking for empty weaklist #135607

Closed

Description

@kumaraditya303

Extension modules which check for self->weakreflist != NULL in tp_dealloc before calling PyObject_ClearWeakRefs(self) leads to to data race if another thread is concurrently mutating the weaklist.
In free-threading the weaklist is modified atomically as such it can cause data race with the non atomic reads in extension modules. This can be avoided in extension modules by calling PyObject_ClearWeakRefs always and removing checking for weaklist == NULL.

I'll try to find a smaller reproducer for this.

Linked PRs

Activity

  1. colesbury commented on Jun 17, 2025

    @colesbury
    Contributor

    The explanation is clear. I don't think you need to find a repro for this.

  2. added 2 commits that reference this issue on Jun 30, 2025
  3. added 4 commits that reference this issue on Jun 30, 2025
  4. added a commit that references this issue on Jul 11, 2025
  5. added a commit that references this issue on Jul 12, 2025
  6. added a commit that references this issue on Jul 13, 2025
  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions