Skip to content

Data race in gc_collect_internal on gcstate->last_mem #134801

Closed
@colesbury

Description

@colesbury

Bug report

Bug description:

Races assigning to __dict__ should be thread safe ... ==================
WARNING: ThreadSanitizer: data race (pid=3951040)
  Write of size 8 at 0x555555f78438 by thread T60:
    #0 gc_collect_internal /home/sgross/cpython/Python/gc_free_threading.c:2248:30 (python+0x59a09e) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)
    #1 gc_collect_main /home/sgross/cpython/Python/gc_free_threading.c:2313:5 (python+0x595027) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)
    #2 _Py_RunGC /home/sgross/cpython/Python/gc_free_threading.c:2762:5 (python+0x595bd5) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)
    #3 _Py_HandlePending /home/sgross/cpython/Python/ceval_gil.c:1395:9 (python+0x5aa283) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)

...

  Previous read of size 8 at 0x555555f78438 by thread T62:
    #0 gc_should_collect_mem_usage /home/sgross/cpython/Python/gc_free_threading.c:2065:36 (python+0x596f36) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)
    #1 gc_should_collect /home/sgross/cpython/Python/gc_free_threading.c:2103:12 (python+0x596f36)
    #2 record_allocation /home/sgross/cpython/Python/gc_free_threading.c:2120:13 (python+0x595b08) (BuildId: 29173f71c99127c1e5ec9850aea4c8892a29468f)
    #3 _PyObject_GC_Link /home/sgross/cpython/Python/gc_free_threading.c:2753:5 (python+0x595b08)

cc @nascheme

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions