FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: do not deadlock sysmon debug logging when covering stdlib by DSeaStar · Pull Request #2260 · coveragepy/coveragepy · GitHub

fix: do not deadlock sysmon debug logging when covering stdlib - #2260

Open
DSeaStar wants to merge 5 commits into
coveragepy:mainfrom
DSeaStar:fix-sysmon-log-reentrancy-2087
Open

fix: do not deadlock sysmon debug logging when covering stdlib#2260
DSeaStar wants to merge 5 commits into
coveragepy:mainfrom
DSeaStar:fix-sysmon-log-reentrancy-2087

Conversation

Copy link
Copy Markdown

Fixes #2087.

COVERAGE_SYSMON_LOG=1 writes debug output from log() with ordinary file I/O and a stack walk. Those operations re-enter sys.monitoring while the sysmon core is measuring the standard library, so test_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 into log().

A subprocess regression test runs a cover_pylib=True measurement with COVERAGE_SYSMON_LOG=1 and COVERAGE_CORE=sysmon.

DSeaStar and others added 5 commits August 14, 2026 20:26
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>
The debug logger opened "/tmp/foo.out" unconditionally; on Windows CI
runners the /tmp directory does not exist, so
test_sysmon_log_does_not_deadlock_on_stdlib failed with
FileNotFoundError before the deadlock could even be exercised. Resolve
the log path through tempfile.gettempdir(), which always exists.

Signed-off-by: SeaStar Deng <172368758@qq.com>
Resolve CHANGES.rst conflict: keep upstream's new Unreleased entries and
append the issue 2087 note plus its link target.

DSeaStar commented Aug 24, 2026
edited
Loading

Copy link
Copy Markdown
Author

Branch updated: it had drifted out of date with main and CHANGES.rst no longer merged cleanly (the Unreleased section gained several new entries). I merged current main into the branch and resolved that conflict by keeping all of the upstream entries and appending the issue 2087 note (plus its link target) at the end of the list.

No code changes were needed: coverage/sysmon.py and tests/test_sysmon.py merged cleanly, and the upstream MonitorReturn = DISABLE_TYPE | None modernization is preserved. The diff against main is still just the three files. CI is re-running on the new head.

Copy link
Copy Markdown
Author

All CI checks are now green on the rebased branch (merge commit d88cf7cc, which brings in latest main): Dependency Review, CodeQL, Coverage, Tests, and Quality all pass. The only change beyond the original 2-file source diff is CHANGES.rst (conflict resolution — the issue 2087 entry is appended after the upstream Unreleased entries, no code semantics changed). The PR is now mergeable and ready for review/merge. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COVERAGE_SYSMON_LOG=1 causes a deadlock in test_stdlib[True]

1 participant


Back | FazBrowse Home | New Git URL