Skip to content

Debugger hangs due to runtime deadlock. #126096

Closed

Description

@auott

Description

#123650 was closed and fixed by #123651.
However, the issue can still reproduce even with the fix applied, see original issue for stacks.

Reproduction Steps

Debug a dotnet 10 application with VS.

Expected behavior

Debuggee run as expected.

Actual behavior

Runtime can deadlock internally.

Regression?

No response

Known Workarounds

None known.

Configuration

.NET 10 windows x64 is where the issue was spotted but code analysis suggests the race condition could probably be hit on other .NET versions, OSes, and architectures if timed properly.

Other information

No response

Activity

  1. added
    untriaged
    on Mar 25, 2026
  2. dotnet-policy-service commented on Mar 25, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @thaystg, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  3. added and removed
    untriaged
    on Mar 27, 2026
  4. dotnet-policy-service commented on Mar 27, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  5. hoyosjs commented on Mar 27, 2026

    @hoyosjs
    Member

    In the repro cases shared I can see 10.0.5 being run. In it the debugger is stopped on events, and the runtime has a few threads waiting to send events - JIT events, exceptions, potentially the reply to the message itself - but they can't since the DebuggerControllerLock is being held in this similar case:

    coreclr!CLREventWaitHelper+0x12 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\synch.cpp @ 397] 
    coreclr!Thread::WaitSuspendEventsHelper+0x7a [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threadsuspend.cpp @ 4465] 
    coreclr!Thread::WaitSuspendEvents+0x8 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threadsuspend.cpp @ 4497] 
    coreclr!Thread::RareDisablePreemptiveGC+0x9a [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threadsuspend.cpp @ 2185] 
    coreclr!Thread::DisablePreemptiveGC+0x16 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threads.h @ 1288] 
    coreclr!GCHolderBase::EnterInternalCoop_HackNoThread+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threads.h @ 4598] 
    coreclr!GCCoopHackNoThread::{ctor}+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\threads.h @ 4813] 
    coreclr!HashMap::LookupValue+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\hash.cpp @ 552] 
    coreclr!PtrHashMap::LookupValue+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\hash.h @ 607] 
    coreclr!ReadyToRunInfo::GetMethodDescForEntryPointInNativeImage+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\readytoruninfo.cpp @ 376] 
    coreclr!ReadyToRunInfo::GetMethodDescForEntryPoint+0x10b [D:\a\_work\1\s\src\runtime\src\coreclr\vm\readytoruninfo.cpp @ 104] 
    coreclr!ReadyToRunJitManager::JitCodeToMethodInfo+0x2f6 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\codeman.cpp @ 6472] 
    coreclr!EECodeInfo::Init+0xad [D:\a\_work\1\s\src\runtime\src\coreclr\vm\jitinterface.cpp @ 15025] 
    coreclr!EECodeInfo::{ctor}+0x2f [D:\a\_work\1\s\src\runtime\src\coreclr\vm\codeman.h @ 2881] 
    coreclr!EEDbgInterfaceImpl::GetMethodRegionInfo+0x53 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\eedbginterfaceimpl.cpp @ 549] 
    coreclr!CodeRegionInfo::InitializeFromStartAddress+0x2f [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\debugger.h @ 1359] 
    coreclr!CodeRegionInfo::GetCodeRegionInfo+0xab [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\debugger.cpp @ 3104] 
    coreclr!DebuggerController::BindPatch+0x7e [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\controller.cpp @ 1457] 
    coreclr!DebuggerController::AddBindAndActivatePatchForMethodDesc+0xd0 [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\controller.cpp @ 2244] 
    coreclr!DebuggerController::AddBindAndActivateILReplicaPatch+0x105 [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\controller.cpp @ 2019] 
    coreclr!Debugger::MapPatchToDJI+0x43 [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\debugger.cpp @ 4963] 
    coreclr!Debugger::MapAndBindFunctionPatches+0x218 [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\debugger.cpp @ 4879] 
    coreclr!Debugger::JITComplete+0xabad7 [D:\a\_work\1\s\src\runtime\src\coreclr\debug\ee\debugger.cpp @ 2525] 
    coreclr!ReadyToRunInfo::GetEntryPoint+0x12b9 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\readytoruninfo.cpp @ 1284] 
    

    So, the fence post did move a little - We didn't call GetJitInfo during BindPatch for this case looks like, but we end up in another hash lookup during:

    CodeRegionInfo::GetCodeRegionInfo(NULL, NULL, startAddr).OffsetToAddress(patch->offset);

    And potentially any thread starter or JIT complete notification when the debugger is attached is going to hit this race too... For example, in Debugger::JITComplete we do create the DJI before holding the controller lock in MapAndBindFunctionPatches, but any PtrHashMap/HashMap lookup after is going to cause issues. In particular, this one is needed to find the cold/hot split in the method. I need to investigate a little more since the DJI already seems to have the data initialized, so it's unclear why it went down this path. I'd have expected preinitialization to be a good workaround for the stack in particular.

  6. hoyosjs commented on Mar 27, 2026

    @hoyosjs
    Member

    Another few paths with this issue:

    DebuggerController::DispatchPatchOrSingleStep 
      DebuggerController::ScanForTriggers
        DebuggerStepper::TriggerPatch
          DebuggerJMCStepper::TrapStepInHelper       (line 8050)
            Debugger::GetJitInfo                     (debugger.cpp:2637)
              Debugger::GetJitInfoWorker             (debugger.cpp:2655)
                EEDbgInterfaceImpl::GetNativeCodeStartAddress  (eedbginterfaceimpl.cpp:411)
                  ExecutionManager::GetCodeStartAddress         (codeman.cpp:4978)
                    EECodeInfo::{ctor}                         (jitinterface.cpp:14975)
                      EECodeInfo::Init                         (jitinterface.cpp:15005)
                        ReadyToRunJitManager::JitCodeToMethodInfo (codeman.cpp:6415)
                          ReadyToRunInfo::GetMethodDescForEntryPoint (readytoruninfo.cpp:94)
                            ReadyToRunInfo::GetMethodDescForEntryPointInNativeImage (readytoruninfo.cpp:376)
                              PtrHashMap::LookupValue          (hash.h:607)
    ...
    

    And notably, GetJitInfo returning null here will git GetCodeRegionInfo's hashmap too.

    Another case for COM and VSD at :

    DebuggerController::DispatchPatchOrSingleStep   ← LOCK ACQUIRED (line 3065)
      DebuggerController::ScanForTriggers            (line 3114)
        DebuggerStepper::TriggerPatch                (line 7333)
          EEDbgInterfaceImpl::GetNativeCodeMethodDesc  (eedbginterfaceimpl.cpp:419)
            ExecutionManager::GetCodeMethodDesc          (codeman.cpp:5005)
              EECodeInfo::{ctor}                         (jitinterface.cpp:14975)
                EECodeInfo::Init                         (jitinterface.cpp:15005)
                  ReadyToRunJitManager::JitCodeToMethodInfo (codeman.cpp:6415)
                    ReadyToRunInfo::GetMethodDescForEntryPoint (readytoruninfo.cpp:94)
                      ReadyToRunInfo::GetMethodDescForEntryPointInNativeImage (readytoruninfo.cpp:376)
                        PtrHashMap::LookupValue          (hash.h:607)
                          HashMap::LookupValue           (hash.cpp:533)
                          ....
    

    SS through R2R (not common):

    DebuggerController::DispatchPatchOrSingleStep   ← LOCK ACQUIRED (line 3065)
      DebuggerController::ScanForTriggers            (line 3114)
        DebuggerStepper::TriggerPatch
          DebuggerStepper::TrapStep                  (walker loop)
            CodeRegionInfo::GetCodeRegionInfo         (line 6173 or 6219)
              CodeRegionInfo::InitializeFromStartAddress (debugger.h:1344)
                EEDbgInterfaceImpl::GetMethodRegionInfo  (eedbginterfaceimpl.cpp:529)
                  EECodeInfo::{ctor}                     (jitinterface.cpp:14975)
                    EECodeInfo::Init                     (jitinterface.cpp:15005)
                      ReadyToRunJitManager::JitCodeToMethodInfo (codeman.cpp:6415)
                        ReadyToRunInfo::GetMethodDescForEntryPoint (readytoruninfo.cpp:94)
                          ReadyToRunInfo::GetMethodDescForEntryPointInNativeImage (readytoruninfo.cpp:376)
                            PtrHashMap::LookupValue      (hash.h:607)
    

    Also pretty much anything that touches r2r with this shape:

     GetJitInfoFromAddr(addr)
       → GetNativeCodeMethodDesc(addr) → EECodeInfo(addr) → HashMap
       → GetJitInfo(fd, addr)
         → GetNativeCodeStartAddress(addr) → EECodeInfo(addr) → HashMap
         → FindOrCreateInitAndAddJitInfo → Init → InitializeFromStartAddress
           → GetMethodRegionInfo → EECodeInfo(addr) → HashMap
    
  7. hoyosjs commented on Mar 28, 2026

    @hoyosjs
    Member

    #126247 has a workaround for the 2 cases that have been reported in the wild.

  8. hoyosjs commented on Apr 22, 2026

    @hoyosjs
    Member

    As a possible workaround for folks hitting this: Setting DOTNET_ReadyToRun=0 before debugging should avoid most of the cases where this could happen.

  9. hoyosjs commented on Jul 11, 2026

    @hoyosjs
    Member

    main already solved this via EBR

  10. 6 remaining items

  11. modified the milestones: 11.0.0, 12.0.0 on Aug 24, 2026
  12. hoyosjs commented on Sep 2, 2026

    @hoyosjs
    Member

    On release/10.0, the debugger can deadlock while binding an IL breakpoint to ReadyToRun code. A thread holds CrstDebuggerController, lazily loads the method's sequence map, and enters HashMap::LookupValue. The lookup transitions the thread from preemptive to cooperative GC mode. If debugger suspension is active, the transition blocks while the controller lock remains held, preventing debugger synchronization from completing.

    ReadyToRunInfo::GetEntryPoint
      -> Debugger::JITComplete
      -> MapAndBindFunctionPatches
      -> MapPatchToDJI
      -> AddBindAndActivateILReplicaPatch
      -> LazyInitBounds
      -> ReadyToRunJitManager::GetBoundariesAndVars
      -> EECodeInfo
      -> GetMethodDescForEntryPointInNativeImage
      -> HashMap::LookupValue
      -> DisablePreemptiveGC
    

    The required conditions are:

    • A debugger is attached.
    • ReadyToRun code is being activated.
    • A matching IL breakpoint needs to be bound.
    • The method's sequence map has not been initialized.
    • A GC or debugger suspension races with the lookup.

    Other controller-lock-held paths can reach the same transition through GetJitInfo, GetJitInfoFromAddr, GetNativeCodeMethodDesc, GetNativeCodeStartAddress, or CodeRegionInfo. This includes breakpoint binding, JMC step-in, COM/VSD stepping, and single-stepping through ReadyToRun code.

    It is separate from the shutdown/ThreadStore deadlock mentioned above. Current main avoids this transition through ebr but that's a riskier port. release/10.0 remains vulnerable in the LazyInitBounds path.

  13. steveisok commented on Sep 2, 2026

    @steveisok
    Member

    @hoyosjs how risky would #124307 be to backport?

  14. steveisok commented on Sep 2, 2026

    @steveisok
    Member

    Alternatives may be more a game of whack-a-mole.

  15. locked and limited conversation to collaborators on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions