-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Type slots are not thread-safe in free-threaded builds #127266
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
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
For future reference, you can reproduce this race by running the following test with TSAN enabled:
|
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Feb 7, 2025
Fix a few thread-safety bugs to enable test_opcache when run with TSAN: * Use relaxed atomics when clearing `ht->_spec_cache.getitem` (pythongh-115999) * Add temporary suppression for type slot modifications (pythongh-127266) * Use atomic load when reading `*dictptr`
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Feb 10, 2025
Fix a few thread-safety bugs to enable test_opcache when run with TSAN: * Use relaxed atomics when clearing `ht->_spec_cache.getitem` (pythongh-115999) * Add temporary suppression for type slot modifications (pythongh-127266) * Use atomic load when reading `*dictptr`
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Feb 26, 2025
Fix a few thread-safety bugs to enable test_opcache when run with TSAN: * Use relaxed atomics when clearing `ht->_spec_cache.getitem` (pythongh-115999) * Add temporary suppression for type slot modifications (pythongh-127266) * Use atomic load when reading `*dictptr` (cherry picked from commit f151d27) Co-authored-by: Sam Gross <[email protected]>
This was referenced Mar 11, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Mar 26, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Mar 27, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 1, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 17, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 22, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 23, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 23, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 25, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 28, 2025
nascheme
added a commit
that referenced
this issue
Apr 28, 2025
In the free-threaded build, avoid data races caused by updating type slots or type flags after the type was initially created. For those (typically rare) cases, use the stop-the-world mechanism. Remove the use of atomics when reading or writing type flags. The use of atomics is not sufficient to avoid races (since flags are sometimes read without a lock and without atomics) and are no longer required.
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 29, 2025
…thongh-131174) This is triggering deadlocks in test_opcache.
nascheme
added a commit
that referenced
this issue
Apr 29, 2025
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 29, 2025
In the free-threaded build, avoid data races caused by updating type slots or type flags after the type was initially created. For those (typically rare) cases, use the stop-the-world mechanism. Remove the use of atomics when reading or writing type flags. The use of atomics is not sufficient to avoid races (since flags are sometimes read without a lock and without atomics) and are no longer required.
nascheme
added a commit
to nascheme/cpython
that referenced
this issue
Apr 29, 2025
In the free-threaded build, avoid data races caused by updating type slots or type flags after the type was initially created. For those (typically rare) cases, use the stop-the-world mechanism. Remove the use of atomics when reading or writing type flags. The use of atomics is not sufficient to avoid races (since flags are sometimes read without a lock and without atomics) and are no longer required.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
Modification of type slots is protected by the global type lock, however, type slots are read non-atomically without holding the type lock. For example, in
PyObject_SetItem
:cpython/Objects/abstract.c
Lines 231 to 235 in 5bb059f
It's not clear how we want to address this. From @colesbury in #127169 (comment):
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: