Skip to content

TSan: data race with PyTypeObject version tag  #116909

Closed

Description

@pitrou

Bug report

Bug description:

Running test_capi with TSan enabled and the GIL enabled yields the following race condition:

test_isolated_subinterpreter (test.test_capi.test_misc.TestPendingCalls.test_isolated_subinterpreter) ... 
==================
WARNING: ThreadSanitizer: data race (pid=84714)
  Read of size 4 at 0x55c8c4c10f90 by thread T1:
    #0 assign_version_tag /home/antoine/cpython/default/Objects/typeobject.c:1012:13 (python+0x327919) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #1 _PyType_Lookup /home/antoine/cpython/default/Objects/typeobject.c:5087:23 (python+0x3290ab) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #2 _PyObject_GetMethod /home/antoine/cpython/default/Objects/object.c:1462:23 (python+0x2d9f67) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #3 _PyEval_EvalFrameDefault /home/antoine/cpython/default/Python/generated_cases.c.h:3561:25 (python+0x443799) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #4 _PyEval_EvalFrame /home/antoine/cpython/default/./Include/internal/pycore_ceval.h:114:16 (python+0x26cd12) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #5 gen_send_ex2 /home/antoine/cpython/default/Objects/genobject.c:228:24 (python+0x26cd12)
    #6 gen_iternext /home/antoine/cpython/default/Objects/genobject.c:586:9 (python+0x26a0d2) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #7 builtin_next /home/antoine/cpython/default/Python/bltinmodule.c:1534:11 (python+0x4172a3) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
[...]

  Previous write of size 4 at 0x55c8c4c10f90 by main thread:
    #0 assign_version_tag /home/antoine/cpython/default/Objects/typeobject.c (python+0x32794d) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #1 _PyType_Lookup /home/antoine/cpython/default/Objects/typeobject.c:5087:23 (python+0x3290ab) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #2 _PyObject_GetMethod /home/antoine/cpython/default/Objects/object.c:1462:23 (python+0x2d9f67) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #3 _PyEval_EvalFrameDefault /home/antoine/cpython/default/Python/generated_cases.c.h:3561:25 (python+0x443799) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #4 _PyEval_EvalFrame /home/antoine/cpython/default/./Include/internal/pycore_ceval.h:114:16 (python+0x26cd12) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #5 gen_send_ex2 /home/antoine/cpython/default/Objects/genobject.c:228:24 (python+0x26cd12)
    #6 gen_iternext /home/antoine/cpython/default/Objects/genobject.c:586:9 (python+0x26a0d2) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #7 builtin_next /home/antoine/cpython/default/Python/bltinmodule.c:1534:11 (python+0x4172a3) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Mar 16, 2024
  2. pitrou commented on Mar 16, 2024

    @pitrou
    MemberAuthor
  3. pitrou commented on Mar 16, 2024

    @pitrou
    MemberAuthor

    From what I can see, the problem is accessing _PyRuntime.types.next_version_tag without synchronization and without atomic instructions.

  4. added a commit that references this issue on May 25, 2025
  5. kumaraditya303 commented on Jul 4, 2025

    @kumaraditya303
    Contributor

    Fixed by #135794

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions