mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-120158: Fix inconsistent monitoring state when setting events too frequently (gh-141845) (gh-141879)
If we overflowed the global version counter (i.e., after 2*24 calls to
`_PyMonitoring_SetEvents`), we bailed out after setting global monitoring
events but before instrumenting code objects, which led to assertion errors
later on.
Also add a `time.sleep()` to `test_free_threading.test_monitoring` to avoid
overflowing the global version counter.
(cherry picked from commit e457d60daa)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
59ab1edb00
commit
1a798d30d8
3 changed files with 6 additions and 1 deletions
|
|
@ -73,6 +73,9 @@ def test_instrumentation(self):
|
||||||
break
|
break
|
||||||
|
|
||||||
self.during_threads()
|
self.during_threads()
|
||||||
|
# Sleep to avoid setting monitoring events too rapidly and
|
||||||
|
# overflowing the global version counter
|
||||||
|
time.sleep(0.0001)
|
||||||
|
|
||||||
self.after_test()
|
self.after_test()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix inconsistent state when enabling or disabling monitoring events too many
|
||||||
|
times.
|
||||||
|
|
@ -2019,12 +2019,12 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
|
||||||
if (existing_events == events) {
|
if (existing_events == events) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
set_events(&interp->monitors, tool_id, events);
|
|
||||||
uint32_t new_version = global_version(interp) + MONITORING_VERSION_INCREMENT;
|
uint32_t new_version = global_version(interp) + MONITORING_VERSION_INCREMENT;
|
||||||
if (new_version == 0) {
|
if (new_version == 0) {
|
||||||
PyErr_Format(PyExc_OverflowError, "events set too many times");
|
PyErr_Format(PyExc_OverflowError, "events set too many times");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
set_events(&interp->monitors, tool_id, events);
|
||||||
set_global_version(tstate, new_version);
|
set_global_version(tstate, new_version);
|
||||||
#ifdef _Py_TIER2
|
#ifdef _Py_TIER2
|
||||||
_Py_Executors_InvalidateAll(interp, 1);
|
_Py_Executors_InvalidateAll(interp, 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue