Skip to content

HandleTable mutated without the GIL via _pm_release (suspected race) #117

Closed

Description

@b-re-w

Found while investigating #98 (by reading, not observed): UpcallTrampoline.releaseObject, reached through ctypes _pm_release (which releases the GIL around the foreign call), mutates HandleTable without the GIL, while AsyncUpcall.kt states every HandleTable mutation happens under the GIL. Under free-threaded or concurrent use this can corrupt the table.

Completion: either prove the call holds a lock that makes it safe (and document it), or take the GIL / the table's own lock on that path; a concurrency stress test (many threads releasing and registering handles) passes under -PpythonFreeThreaded=true and default.

Activity

  1. added a commit that references this issue on Oct 25, 2026
  2. b-re-w commented on Oct 25, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #302. Cause confirmed: ctypes CFUNCTYPE drops the GIL around _pm_release/_pm_resolve. HandleTable now owns a PlatformMutex.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions