Repository navigation
Conversation
Add a mutex which protects access to the handler map under normal access. We delebrately do not have a lock in PyErr_SetInterruptEx due to deadlock concerns.
| that PyErr_SetInterrupt is async-signal-safe. */ | ||
| _Py_atomic_store_ptr(&Handlers[i].func, func); | ||
| FT_MUTEX_LOCK_FLAGS(&_PyRuntime.signals.handlers_mutex, | ||
| _Py_LOCK_DONT_DETACH); |
There was a problem hiding this comment.
Believe setting this flag will ensure that the lock is released before a stop the world before the fork, and this also helps on shutdown too ensure we wait for the lock to be released by any attaching threads.
|
This looks like a reasonable incremental fix to me. The lock protects taking a reference, with callbacks and decrefs happening after unlocking. It also leaves room to fix Could we consider |
This helps offer some partial protection for sub interpretors
|
|
||
| @support.requires_fork() | ||
| @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") | ||
| def test_fork_with_handler_lock_held(self): |
There was a problem hiding this comment.
A bit on the fence about this test since it mutates the internal state setting a lock before fork. Believe this is the only approach to reliably test that we don't hold the mutex on fork
regrtest's per-test timeout runs a faulthandler watchdog thread, so os.fork() warns, and CI's -W error turns the warning into an error.
Add a mutex which protects access to the handler map under normal access. We delebrately do not have a lock in PyErr_SetInterruptEx due to deadlock concerns.
This is an alternative proposal to leveraging lock free QSBR approach
signalmodule.cin free-threaded Python #161235