Skip to content

TSan: data race in pending calls #116908

@pitrou

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)
  Write of size 4 at 0x7f72e30d2038 by main thread:
    #0 _push_pending_call /home/antoine/cpython/default/Python/ceval_gil.c:674:25 (python+0x4b860b) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #1 _PyEval_AddPendingCall /home/antoine/cpython/default/Python/ceval_gil.c:746:18 (python+0x4b860b)
    #2 pending_identify /home/antoine/cpython/default/./Modules/_testinternalcapi.c:1135:13 (_testinternalcapi.cpython-313d-x86_64-linux-gnu.so+0x8d77) (BuildId: 0997eb086570be7275cd70cbfb0545cf77f5f79c)
    #3 cfunction_call /home/antoine/cpython/default/Objects/methodobject.c:551:18 (python+0x2cf92c) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)

[...]
  Previous atomic read of size 4 at 0x7f72e30d2038 by thread T1 (mutexes: write M0):
    #0 _Py_atomic_load_int32_relaxed /home/antoine/cpython/default/./Include/cpython/pyatomic_gcc.h:319:10 (python+0x4b7cfc) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #1 update_eval_breaker_for_thread /home/antoine/cpython/default/Python/ceval_gil.c:87:27 (python+0x4b7cfc)
    #2 take_gil /home/antoine/cpython/default/Python/ceval_gil.c:385:5 (python+0x4b7cfc)
    #3 _PyEval_AcquireLock /home/antoine/cpython/default/Python/ceval_gil.c:555:5 (python+0x4b81be) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #4 _PyThreadState_Attach /home/antoine/cpython/default/Python/pystate.c:1878:5 (python+0x525943) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #5 PyEval_RestoreThread /home/antoine/cpython/default/Python/ceval_gil.c:623:5 (python+0x4b843e) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #6 _Py_write_impl /home/antoine/cpython/default/Python/fileutils.c:1970:13 (python+0x561f0e) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #7 _Py_write /home/antoine/cpython/default/Python/fileutils.c:2036:12 (python+0x561e1f) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #8 os_write_impl /home/antoine/cpython/default/./Modules/posixmodule.c:11495:12 (python+0x579d37) (BuildId: 80a378e5bf8e9a3b503d1ddb455283576a308db6)
    #9 os_write /home/antoine/cpython/default/./Modules/clinic/posixmodule.c.h:7369:21 (python+0x579d37)
[...]

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions