Skip to content

Possible data race between specialize_attr_loadclassattr and ensure_nonmanaged_dict under free-threading #132643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vfdev-5 opened this issue Apr 17, 2025 · 2 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@vfdev-5
Copy link

vfdev-5 commented Apr 17, 2025

Bug report

Bug description:

I built main branch and observed the following races under free-threading in cpython 3.14 (Python 3.14.0a7+ experimental free-threading build (heads/main:e42bda94411, Apr 17 2025, 14:08:39) [Clang 18.1.3 (1ubuntu1)])

Race
==================
WARNING: ThreadSanitizer: data race (pid=921410)
  Read of size 8 at 0x7fffd22b01b8 by thread T13 (mutexes: read M0):
    #0 specialize_attr_loadclassattr /project/cpython/Python/specialize.c:1644:30 (python3.14+0x4ddf68) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #1 do_specialize_instance_load_attr /project/cpython/Python/specialize.c:1163:21 (python3.14+0x4d9fa1) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #2 specialize_instance_load_attr /project/cpython/Python/specialize.c:1340:18 (python3.14+0x4d9fa1)
    #3 _Py_Specialize_LoadAttr /project/cpython/Python/specialize.c:1368:16 (python3.14+0x4d9fa1)
    #4 _PyEval_EvalFrameDefault /project/cpython/Python/generated_cases.c.h:7674:21 (python3.14+0x410c34) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #5 _PyEval_EvalFrame /project/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.14+0x3f80f0) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #6 _PyEval_Vector /project/cpython/Python/ceval.c:1917:12 (python3.14+0x3f80f0)

...

  Previous atomic write of size 8 at 0x7fffd22b01b8 by thread T8 (mutexes: read M0):
    #0 _Py_atomic_store_ptr_release /project/cpython/./Include/cpython/pyatomic_gcc.h:565:3 (python3.14+0x283dbd) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #1 ensure_nonmanaged_dict /project/cpython/Objects/dictobject.c:7496:9 (python3.14+0x283dbd)
    #2 _PyObjectDict_SetItem /project/cpython/Objects/dictobject.c:7532:12 (python3.14+0x283e8e) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #3 _PyObject_GenericSetAttrWithDict /project/cpython/Objects/object.c:1872:19 (python3.14+0x2aa914) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #4 PyObject_GenericSetAttr /project/cpython/Objects/object.c:1900:12 (python3.14+0x2ab1d7) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #5 PyObject_SetAttr /project/cpython/Objects/object.c:1450:15 (python3.14+0x2a7ada) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #6 _PyEval_EvalFrameDefault /project/cpython/Python/generated_cases.c.h:10653:27 (python3.14+0x4197db) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #7 _PyEval_EvalFrame /project/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.14+0x3f80f0) (BuildId: d491981d76fd0b67bcb5e01a978d07da019800b8)
    #8 _PyEval_Vector /project/cpython/Python/ceval.c:1917:12 (python3.14+0x3f80f0)
 

Full report: https://gist.github.com/vfdev-5/18a83532a8589b02cd01ac21342727f6

cc @hawkinsp

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@vfdev-5 vfdev-5 added the type-bug An unexpected behavior, bug, or error label Apr 17, 2025
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading labels Apr 17, 2025
@kumaraditya303
Copy link
Contributor

I think the loading of dict in specialization path should do an load on the object with offset using acquire memory ordering.

@colesbury
Copy link
Contributor

Yeah, that sounds right to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants