Lease debugger sessions across commands - #6046
Merged
Merged
Conversation
Keep a pooled debugger host locked across command sequences that temporarily change debugger-global state, preventing dbgout from leaking into concurrent tests. Simplify dump host slot ownership and keep DbgEng capture concurrency separately bounded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Add a cross-owner contention test proving a second session cannot acquire a slot before the outer lease is disposed.
Pull request overview
Adds disposable debugger-session leases to keep pooled dump hosts exclusive across multi-command sequences and isolate dbgout state.
Changes:
- Adds reentrant host-slot leases and bounded pooling.
- Protects the
dbgoutcommand sequence with a lease. - Separates DbgEng capture serialization from dump-host pooling.
File summaries
| File | Summary |
|---|---|
src/tests/SOS.Tests/MiscCommandTests.cs |
Holds a lease during dbgout operations. |
src/tests/SOS.Tests/HostSlotTests.cs |
Updates slot tests and adds lease coverage. |
src/tests/SOS.TestHarness/Targets.cs |
Simplifies pooled-host teardown. |
src/tests/SOS.TestHarness/Target.cs |
Adds the debugger-session lease API. |
src/tests/SOS.TestHarness/HostSlot.cs |
Implements pooled host ownership and leases. |
src/tests/SOS.TestHarness/DumpSession.cs |
Uses pooled slots for dump commands. |
src/tests/SOS.TestHarness/DeadTarget.cs |
Forwards lease acquisition to dump sessions. |
src/tests/SOS.TestHarness/DbgEngCapturer.cs |
Adds independent capture serialization. |
Review details
Suppressed comments (1)
src/tests/SOS.Tests/HostSlotTests.cs:113
- This test only exercises reentrant acquisition by the same owner. It never tries to acquire the slot from a different owner while the outer lease is held, so it would still pass if the lease released the monitor between commands—the cross-session exclusivity that fixes the reported dbgout race is untested. Add a scheduler-safe contention assertion that a second owner cannot acquire until the outer lease is disposed.
using (slot.Acquire(owner))
{
using (slot.Acquire(owner))
{
owner.Host.Sos("first");
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
steveisok
approved these changes
Sep 17, 2026
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.
Summary
dbgoutenable/use/disable sequenceRoot cause
dbgoutchanges global state in the loaded SOS instance. Dump debugger hosts are pooled, but the existing slot lock covered each command independently. After one test enableddbgout, another test could acquire the same physical debugger before the first test disabled it.On .NET Framework dumps,
clrstack -all -rcan encounter native IPs that cannot be mapped back to managed source information. Withdbgoutunexpectedly enabled, those diagnostics were emitted into the command's tabular output while a row was being assembled. The test parser then interpreted the diagnostic text as part of the row and failed its register validation.Fix
AcquireDebuggerSessionnow returns a disposable lease over the existing host-slot monitor. TheSessionCommands_Executetest holds that lease fromdbgoutthrough the commands under test and thedbgout -offcleanup. Nested command acquisitions are reentrant on the same thread, so the same physical debugger remains exclusively owned until its global state is restored.Testing
src/tests/SOS.Tests/SOS.Tests.csproj: zero warnings and errorsHostSlotTests: 4 passedSessionCommands_ExecuteandClrStack_Registerstogether for Framework/CDB dumps five times: 25 passedCI failure
Addresses the Framework
ClrStack_Registersfailure in build 1598637.