Skip to content

Lease debugger sessions across commands - #6046

Merged
max-charlamb merged 1 commit into
mainfrom
max-charlamb/scoped-debugger-session
Sep 18, 2026
Merged

max-charlamb merged 1 commit into
mainfrom
max-charlamb/scoped-debugger-session

Conversation

@max-charlamb

Copy link
Copy Markdown
Member

Summary

  • add a disposable debugger-session lease that keeps one pooled debugger host locked across multiple commands
  • use the lease around the dbgout enable/use/disable sequence
  • simplify dump-session slot ownership now that every dump debugger uses a bounded host pool
  • keep in-process DbgEng dump capture concurrency separate from pooled dump analysis

Root cause

dbgout changes global state in the loaded SOS instance. Dump debugger hosts are pooled, but the existing slot lock covered each command independently. After one test enabled dbgout, another test could acquire the same physical debugger before the first test disabled it.

On .NET Framework dumps, clrstack -all -r can encounter native IPs that cannot be mapped back to managed source information. With dbgout unexpectedly 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

AcquireDebuggerSession now returns a disposable lease over the existing host-slot monitor. The SessionCommands_Execute test holds that lease from dbgout through the commands under test and the dbgout -off cleanup. Nested command acquisitions are reentrant on the same thread, so the same physical debugger remains exclusively owned until its global state is restored.

Testing

  • built src/tests/SOS.Tests/SOS.Tests.csproj: zero warnings and errors
  • ran HostSlotTests: 4 passed
  • ran SessionCommands_Execute and ClrStack_Registers together for Framework/CDB dumps five times: 25 passed

CI failure

Addresses the Framework ClrStack_Registers failure in build 1598637.

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
Copilot AI lite review requested due to automatic review settings September 17, 2026 19:44
@max-charlamb
max-charlamb requested a review from a team as a code owner September 17, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 dbgout command 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.

@max-charlamb
max-charlamb merged commit 7940275 into main Sep 18, 2026
24 checks passed
@max-charlamb
max-charlamb deleted the max-charlamb/scoped-debugger-session branch September 18, 2026 14:01
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.

3 participants