Skip to content

TSan data races from test_queue with free threading #133473

Closed
@zackw

Description

@zackw

Bug report

Bug description:

In a --with-thread-sanitizer --disable-gil build, running the test_queue test with high levels of --parallel-threads causes TSan to report several data races within the garbage collector. All appear low-severity to me -- the worst they can do is cause the garbage collector to make bad decisions about whether to run a collection -- but I thought I'd report them anyway.

Stack traces have been truncated as how we got into the garbage collector isn't germane to the problem, and each individual conflict is only noted once.

$ ./python -E -Wd -m test --parallel-threads 16 test_queue
Using random seed: 3119004105
0:00:00 load avg: 0.87 Run 1 test sequentially in a single process
0:00:00 load avg: 0.87 [1/1] test_queue
==================
WARNING: ThreadSanitizer: data race (pid=373472)
  Write of size 4 at 0x55ba3261501c by thread T469:
    #0 gc_should_collect_rss Python/gc_free_threading.c:2072 (python+0x4e9921)
    ...
  Previous atomic read of size 4 at 0x55ba3261501c by thread T481:
    #0 _Py_atomic_load_int_relaxed Include/cpython/pyatomic_gcc.h:307 (python+0x4e978b)
    #1 gc_should_collect Python/gc_free_threading.c:2081 (python+0x4e978b)
    ...

  Atomic read of size 8 at 0x55ba32615100 by thread T481:
    #0 _Py_atomic_load_ssize_relaxed Include/cpython/pyatomic_gcc.h:383 (python+0x4e9829)
    #1 gc_should_collect_rss Python/gc_free_threading.c:2050 (python+0x4e9829)
    ...
  Previous write of size 8 at 0x55ba32615100 by thread T469:
    #0 gc_should_collect_rss Python/gc_free_threading.c:2071 (python+0x4e9912)
    ...

  Write of size 4 at 0x55ba3261501c by thread T493:
    #0 gc_should_collect_rss Python/gc_free_threading.c:2072 (python+0x4e9921)
    ...
  Previous atomic write of size 4 at 0x55ba3261501c by thread T509:
    #0 _Py_atomic_add_int Include/cpython/pyatomic_gcc.h:15 (python+0x4eb18b)
    #1 record_allocation Python/gc_free_threading.c:2111 (python+0x4eb18b)
    ...

  Atomic write of size 4 at 0x55ee8e6c301c by thread T115:
    #0 _Py_atomic_add_int Include/cpython/pyatomic_gcc.h:15 (python+0x4eb18b)
    #1 record_allocation Python/gc_free_threading.c:2111 (python+0x4eb18b)
    ...
  Previous read of size 4 at 0x55ee8e6c301c by thread T114:
    #0 gc_should_collect_rss Python/gc_free_threading.c:2071 (python+0x4e9903)
    ...

  Write of size 8 at 0x558a95f2c0f8 by thread T982:
    #0 gc_collect_internal Python/gc_free_threading.c:2242 (python+0x4f1227)
    ...
  Previous read of size 8 at 0x558a95f2c0f8 by thread T975:
    #0 gc_should_collect_rss Python/gc_free_threading.c:2060 (python+0x4e9846)
    ...

I can send a patch for these if it is felt to be worthwhile.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions