Skip to content

Conversation

tommcdon
Copy link
Member

This fix correctly manages m_DebugWillSyncCount when thread exits before it is synchronized, addressing #112747

@tommcdon tommcdon added this to the 10.0.0 milestone Apr 22, 2025
@tommcdon tommcdon requested a review from a team April 22, 2025 02:54
@tommcdon tommcdon self-assigned this Apr 22, 2025
@Copilot Copilot AI review requested due to automatic review settings April 22, 2025 02:55
@ghost ghost added the area-VM-coreclr label Apr 22, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the debugger app hang issue on thread termination by correctly managing m_DebugWillSyncCount when a thread exits before synchronization.

  • Added a check for TS_DebugWillSync in OnThreadTerminate
  • Reset the thread state and decremented the debug sync counter accordingly

if (m_State & TS_DebugWillSync)
{
ResetThreadState(TS_DebugWillSync);
InterlockedDecrement(&m_DebugWillSyncCount);
Copy link
Preview

Copilot AI Apr 22, 2025

Choose a reason for hiding this comment

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

Consider adding an assertion or check to ensure that m_DebugWillSyncCount is positive before decrementing to avoid potential underflow if multiple thread terminations occur in succession.

Suggested change
InterlockedDecrement(&m_DebugWillSyncCount);
if (m_DebugWillSyncCount > 0)
{
InterlockedDecrement(&m_DebugWillSyncCount);
}

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Is this is a regression in 9, seems like it is from the bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this is a regression in 9, seems like it is from the bug?

We believe that the issue has always existed, but something in .NET 9 may have caused it to happen more often. Perhaps it is a timing issue.

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@tommcdon tommcdon merged commit 28bbd27 into dotnet:main Apr 22, 2025
96 checks passed
@tommcdon
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/14598643076

tommcdon added a commit to tommcdon/runtime that referenced this pull request May 22, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants