https://github.com/python/cpython/commit/c5180d74e199e5bdb8f1c149dc3e956071ebf365
commit: c5180d74e199e5bdb8f1c149dc3e956071ebf365
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2025-09-15T10:39:41Z
summary:
gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst
M Objects/object.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst
new file mode 100644
index 00000000000000..068f04120daa3a
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst
@@ -0,0 +1,2 @@
+Ensure that :c:func:`PyRefTracer_SetTracer` sync with all existing threads
when called
+to avoid races in the free threaded build. Patch by Pablo Galindo
diff --git a/Objects/object.c b/Objects/object.c
index 2c07c2e9841b0d..c9bcc0c7b09e63 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -3287,6 +3287,8 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
_Py_AssertHoldsTstate();
+
+ _PyEval_StopTheWorldAll(&_PyRuntime);
if (_PyRuntime.ref_tracer.tracer_func != NULL) {
_PyReftracerTrack(NULL, PyRefTracer_TRACKER_REMOVED);
if (PyErr_Occurred()) {
@@ -3295,6 +3297,7 @@ int PyRefTracer_SetTracer(PyRefTracer tracer, void *data)
{
}
_PyRuntime.ref_tracer.tracer_func = tracer;
_PyRuntime.ref_tracer.tracer_data = data;
+ _PyEval_StartTheWorldAll(&_PyRuntime);
return 0;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]