fix: do not deadlock sysmon debug logging when covering stdlib - #2260
Open
DSeaStar wants to merge 3 commits into
Open
fix: do not deadlock sysmon debug logging when covering stdlib#2260DSeaStar wants to merge 3 commits into
DSeaStar wants to merge 3 commits into
Conversation
COVERAGE_SYSMON_LOG=1 re-entered sys.monitoring from log() file I/O, which hung test_stdlib[True]. Ignore nested log calls on the same thread.
When COVERAGE_SYSMON_LOG=1, sys.monitoring is replaced by a LoggingWrapper whose __getattr__ wrapped every attribute access as a function. Reading constants like COVERAGE_ID then returned a function instead of the int, so SysMonitor.start() crashed with "TypeError: '<=' not supported between instances of 'function' and 'int'". Return non-callable attributes unwrapped; only callables are logged. This is required by the new stdlib-logging test that enables the debug log (coveragepy#2087). Signed-off-by: SeaStar Deng <172368758@qq.com>
With COVERAGE_SYSMON_LOG=1, logging a sys.monitoring call inside SysMonitor.start() (which holds self.lock, added for free-threading in 8b9cecc) triggers PY_START events; the sysmon_py_start callback then re-enters the same non-reentrant Lock in the same thread and deadlocks. An RLock lets the callback proceed in the lock-holding thread while still excluding other threads. Verified with the new test_sysmon_log_does_not_deadlock_on_stdlib on CPython 3.14. Signed-off-by: SeaStar Deng <172368758@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2087.
COVERAGE_SYSMON_LOG=1writes debug output fromlog()with ordinary file I/O and a stack walk. Those operations re-entersys.monitoringwhile the sysmon core is measuring the standard library, sotest_stdlib[True]hangs.log()now uses a thread-local guard and drops nested calls on the same thread. The first-thread banner is written in the same call instead of recursing intolog().A subprocess regression test runs a
cover_pylib=Truemeasurement withCOVERAGE_SYSMON_LOG=1andCOVERAGE_CORE=sysmon.