Skip to content

Commit 9966dae

Browse files
authoredFeb 26, 2025··
[3.13] gh-117657: Enable test_opcache under TSAN (GH-129831) (GH-130597)
Fix a few thread-safety bugs to enable test_opcache when run with TSAN: * Use relaxed atomics when clearing `ht->_spec_cache.getitem` (gh-115999) * Add temporary suppression for type slot modifications (gh-127266) * Use atomic load when reading `*dictptr` (cherry picked from commit f151d27)
1 parent 43a2a37 commit 9966dae

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed
 

‎Lib/test/libregrtest/tsan.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'test_importlib',
1414
'test_io',
1515
'test_logging',
16+
'test_opcache',
1617
'test_queue',
1718
'test_signal',
1819
'test_socket',

‎Objects/object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
15841584
else {
15851585
PyObject **dictptr = _PyObject_ComputedDictPointer(obj);
15861586
if (dictptr != NULL) {
1587-
dict = *dictptr;
1587+
dict = FT_ATOMIC_LOAD_PTR_ACQUIRE(*dictptr);
15881588
}
15891589
else {
15901590
dict = NULL;

‎Objects/typeobject.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ type_modified_unlocked(PyTypeObject *type)
10431043
if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
10441044
// This field *must* be invalidated if the type is modified (see the
10451045
// comment on struct _specialization_cache):
1046-
((PyHeapTypeObject *)type)->_spec_cache.getitem = NULL;
1046+
FT_ATOMIC_STORE_PTR_RELAXED(
1047+
((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
10471048
}
10481049
}
10491050

@@ -1119,7 +1120,8 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
11191120
if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
11201121
// This field *must* be invalidated if the type is modified (see the
11211122
// comment on struct _specialization_cache):
1122-
((PyHeapTypeObject *)type)->_spec_cache.getitem = NULL;
1123+
FT_ATOMIC_STORE_PTR_RELAXED(
1124+
((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
11231125
}
11241126
}
11251127

‎Tools/tsan/suppressions_free_threading.txt

+3
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ race_top:PyThreadState_Clear
4747
# Only seen on macOS, sample: https://gist.github.com/aisk/dda53f5d494a4556c35dde1fce03259c
4848
race_top:set_default_allocator_unlocked
4949

50+
# gh-127266: type slot updates are not thread-safe (test_opcache.test_load_attr_method_lazy_dict)
51+
race_top:update_one_slot
52+
5053
# https://gist.github.com/mpage/6962e8870606cfc960e159b407a0cb40
5154
thread:pthread_create

0 commit comments

Comments
 (0)
Please sign in to comment.