gh-99377: Revert audit events for thread state creation and free, because the GIL is not properly held at these times (GH-99543)

This commit is contained in:
Steve Dower 2022-11-17 00:24:16 +00:00 committed by GitHub
parent bc390dd935
commit 5fdd49dc65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 39 deletions

View file

@ -1239,25 +1239,12 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
The global interpreter lock need not be held, but may be held if it is The global interpreter lock need not be held, but may be held if it is
necessary to serialize calls to this function. necessary to serialize calls to this function.
.. audit-event:: cpython.PyThreadState_New id c.PyThreadState_New
Raise an auditing event ``cpython.PyThreadState_New`` with Python's thread
id as the argument. The event will be raised from the thread creating the new
``PyThreadState``, which may not be the new thread.
.. c:function:: void PyThreadState_Clear(PyThreadState *tstate) .. c:function:: void PyThreadState_Clear(PyThreadState *tstate)
Reset all information in a thread state object. The global interpreter lock Reset all information in a thread state object. The global interpreter lock
must be held. must be held.
.. audit-event:: cpython.PyThreadState_Clear id c.PyThreadState_Clear
Raise an auditing event ``cpython.PyThreadState_Clear`` with Python's
thread id as the argument. The event may be raised from a different thread
than the one being cleared. Exceptions raised from a hook will be treated
as unraisable and will not abort the operation.
.. versionchanged:: 3.9 .. versionchanged:: 3.9
This function now calls the :c:member:`PyThreadState.on_delete` callback. This function now calls the :c:member:`PyThreadState.on_delete` callback.
Previously, that happened in :c:func:`PyThreadState_Delete`. Previously, that happened in :c:func:`PyThreadState_Delete`.

View file

@ -197,19 +197,11 @@ class AuditTest(unittest.TestCase):
actual = [(ev[0], ev[2]) for ev in events] actual = [(ev[0], ev[2]) for ev in events]
expected = [ expected = [
("_thread.start_new_thread", "(<test_func>, (), None)"), ("_thread.start_new_thread", "(<test_func>, (), None)"),
("cpython.PyThreadState_New", "(2,)"),
("test.test_func", "()"), ("test.test_func", "()"),
("cpython.PyThreadState_Clear", "(2,)"),
] ]
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def test_threading_abort(self):
# Ensures that aborting PyThreadState_New raises the correct exception
returncode, events, stderr = self.run_python("test_threading_abort")
if returncode:
self.fail(stderr)
def test_wmi_exec_query(self): def test_wmi_exec_query(self):
import_helper.import_module("_wmi") import_helper.import_module("_wmi")

View file

@ -875,11 +875,6 @@ PyThreadState_New(PyInterpreterState *interp)
PyThreadState *tstate = new_threadstate(interp); PyThreadState *tstate = new_threadstate(interp);
if (tstate) { if (tstate) {
_PyThreadState_SetCurrent(tstate); _PyThreadState_SetCurrent(tstate);
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
PyThreadState_Clear(tstate);
_PyThreadState_DeleteCurrent(tstate);
return NULL;
}
} }
return tstate; return tstate;
} }
@ -887,15 +882,7 @@ PyThreadState_New(PyInterpreterState *interp)
PyThreadState * PyThreadState *
_PyThreadState_Prealloc(PyInterpreterState *interp) _PyThreadState_Prealloc(PyInterpreterState *interp)
{ {
PyThreadState *tstate = new_threadstate(interp); return new_threadstate(interp);
if (tstate) {
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
PyThreadState_Clear(tstate);
_PyThreadState_Delete(tstate, 0);
return NULL;
}
}
return tstate;
} }
// We keep this around for (accidental) stable ABI compatibility. // We keep this around for (accidental) stable ABI compatibility.
@ -1043,10 +1030,6 @@ _PyInterpreterState_ClearModules(PyInterpreterState *interp)
void void
PyThreadState_Clear(PyThreadState *tstate) PyThreadState_Clear(PyThreadState *tstate)
{ {
if (PySys_Audit("cpython.PyThreadState_Clear", "K", tstate->id) < 0) {
PyErr_WriteUnraisable(NULL);
}
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
if (verbose && tstate->cframe->current_frame != NULL) { if (verbose && tstate->cframe->current_frame != NULL) {