Skip to content

Commit cbdda9f

Browse files
committed
pythongh-120158: Fix monitoring state when setting events too frequently
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 insturmenting 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.
1 parent 49ff8b6 commit cbdda9f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix inconsistent state when enabling or disabling monitoring events too many
2+
times.

Python/instrumentation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,12 +2021,12 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
20212021
if (existing_events == events) {
20222022
return 0;
20232023
}
2024-
set_events(&interp->monitors, tool_id, events);
20252024
uint32_t new_version = global_version(interp) + MONITORING_VERSION_INCREMENT;
20262025
if (new_version == 0) {
20272026
PyErr_Format(PyExc_OverflowError, "events set too many times");
20282027
return -1;
20292028
}
2029+
set_events(&interp->monitors, tool_id, events);
20302030
set_global_version(tstate, new_version);
20312031
#ifdef _Py_TIER2
20322032
_Py_Executors_InvalidateAll(interp, 1);

0 commit comments

Comments
 (0)