From: Pablo Galindo Salgado Date: Mon, 15 Sep 2025 10:39:41 +0000 (+0100) Subject: gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994) X-Git-Tag: v3.15.0a1~371 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5180d74e199e5bdb8f1c149dc3e956071ebf365;p=thirdparty%2FPython%2Fcpython.git gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994) --- 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 000000000000..068f04120daa --- /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 2c07c2e9841b..c9bcc0c7b09e 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; }