Skip to content
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

Data race between set_richcompare and frozenset_hash under free-threading #132213

Closed
vfdev-5 opened this issue Apr 7, 2025 · 1 comment
Closed
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 7, 2025

Bug report

Bug description:

We have the following TSAN report from coming JAX CI:

==================
 WARNING: ThreadSanitizer: data race (pid=40645)
   Read of size 8 at 0x7fffb6bdc1a0 by thread T6 (mutexes: read M0):
     #0 set_richcompare /__w/jax/jax/cpython/Objects/setobject.c:2144:16 (python3.14+0x2e1904) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #1 do_richcompare /__w/jax/jax/cpython/Objects/object.c:1054:15 (python3.14+0x2a644b) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #2 PyObject_RichCompare /__w/jax/jax/cpython/Objects/object.c:1103:21 (python3.14+0x2a644b)
     #3 _PyEval_EvalFrameDefault /__w/jax/jax/cpython/Python/generated_cases.c.h:4471:35 (python3.14+0x40690b) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #4 _PyEval_EvalFrame /__w/jax/jax/cpython/./Include/internal/pycore_ceval.h:119:16 (python3.14+0x3f7550) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #5 _PyEval_Vector /__w/jax/jax/cpython/Python/ceval.c:1902:12 (python3.14+0x3f7550)
     #6 _PyFunction_Vectorcall /__w/jax/jax/cpython/Objects/call.c (python3.14+0x1f1a8f) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #7 _PyObject_VectorcallTstate /__w/jax/jax/cpython/./Include/internal/pycore_call.h:169:11 (python3.14+0x2f9e4a) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
...
   Previous atomic write of size 8 at 0x7fffb6bdc1a0 by thread T8 (mutexes: read M0):
     #0 _Py_atomic_store_ssize_relaxed /__w/jax/jax/cpython/./Include/cpython/pyatomic_gcc.h:513:3 (python3.14+0x2e22b9) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #1 frozenset_hash /__w/jax/jax/cpython/Objects/setobject.c:801:5 (python3.14+0x2e22b9)
     #2 PyObject_Hash /__w/jax/jax/cpython/Objects/object.c (python3.14+0x2a6c56) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #3 tuple_hash /__w/jax/jax/cpython/Objects/tupleobject.c:321:27 (python3.14+0x2f38bf) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #4 PyObject_Hash /__w/jax/jax/cpython/Objects/object.c (python3.14+0x2a6c56) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)
     #5 builtin_hash /__w/jax/jax/cpython/Python/bltinmodule.c:1736:9 (python3.14+0x3f0d15) (BuildId: 48c7ba326d9f22d081e76424a9d52fc8476e98f5)

Probably missing atomic read here:

if (v->hash != -1 &&

CPython version: Python 3.14.0a6+ experimental free-threading build (heads/main:8680400, Apr 6 2025, 05:24:33) [Clang 18.1.3 (1ubuntu1)]

cc @kumaraditya303

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

@vfdev-5 vfdev-5 added the type-bug An unexpected behavior, bug, or error label Apr 7, 2025
@kumaraditya303 kumaraditya303 self-assigned this Apr 7, 2025
@kumaraditya303
Copy link
Contributor

Created #132215 to fix it

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

3 participants