https://github.com/python/cpython/commit/589382bd04e4326c5582d96f71fe93b3d6365d53 commit: 589382bd04e4326c5582d96f71fe93b3d6365d53 branch: 3.13 author: Kumar Aditya <kumaradi...@python.org> committer: kumaraditya303 <kumaradi...@python.org> date: 2025-03-13T09:41:26Z summary:
[3.13] gh-131141: fix data race in instrumentation while registering callback (#131166) files: A Misc/NEWS.d/next/Core_and_Builtins/2025-03-12-11-19-46.gh-issue-131141.tQz594.rst M Python/instrumentation.c diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-12-11-19-46.gh-issue-131141.tQz594.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-12-11-19-46.gh-issue-131141.tQz594.rst new file mode 100644 index 00000000000000..c1ea679864fb15 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-12-11-19-46.gh-issue-131141.tQz594.rst @@ -0,0 +1 @@ +Fix data race in :data:`sys.monitoring` instrumentation while registering callback. diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 3481b5df14288b..d4bca27f22cd74 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -1399,9 +1399,10 @@ _PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj) PyInterpreterState *is = _PyInterpreterState_GET(); assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS); assert(0 <= event_id && event_id < _PY_MONITORING_EVENTS); - PyObject *callback = _Py_atomic_exchange_ptr(&is->monitoring_callables[tool_id][event_id], - Py_XNewRef(obj)); - + _PyEval_StopTheWorld(is); + PyObject *callback = is->monitoring_callables[tool_id][event_id]; + is->monitoring_callables[tool_id][event_id] = Py_XNewRef(obj); + _PyEval_StartTheWorld(is); return callback; } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com