Skip to content

[release/9.0-staging] Fix debugger app hangs related to thread exit #114917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Apr 22, 2025

Backport of #114887 to release/9.0-staging

/cc @tommcdon

Customer Impact

  • Customer reported
  • Found internally

Description

Debugging a .NET 9 application with Visual Studio can randomly end up freezing the debuggee.
See this issue

Reproduction Steps

Debug an application with many threads that exit while trying to step through code.

Expected behavior

Debuggee does not freeze.

Actual behavior

Debuggee gets stuck with the runtime waiting for all threads to synchronize, but one of the threads being waited has exited so it will never complete.

Regression

  • Yes
  • No

Reported on #112747, originally a VS feedback item. No known commit that caused the regression. Technically this issue has existed for all time but something in .NET 9 changed the timing to expose this issue more often.

Testing

How was the fix verified? Customer verified fix on #112747 (comment).

The following will trigger the bug

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int j = 0;
            int k = 0;
            while (true)
            {
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
                {
                    break;
                }
                Interlocked.Increment(ref k);
                Thread thread = new Thread(() =>
                {
                    Interlocked.Increment(ref i);
                    Interlocked.Decrement(ref k);
                    Thread.Sleep(20);
                });
                 thread.Start();
                if (j++ == 100)
                {
                    j = 0;
                    Console.WriteLine(i + " " + k);
                    Thread.Sleep(200);
                }
            }
        }
    }
}

How was the issue missed previously? Technically the bug has existed for all time. The scenario requires multiple threads being destroyed while debug events are firing in parallel.

What tests were added? Visual Studio testing

Risk

Low - this covers a missed case in thread destroy that does correct bookkeeping for the debugger during suspension

@ghost ghost added the area-VM-coreclr label Apr 22, 2025
Copy link
Contributor

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

@tommcdon tommcdon requested a review from a team April 22, 2025 15:30
@tommcdon tommcdon added this to the 10.0.0 milestone Apr 22, 2025
@tommcdon
Copy link
Member

cc @dotnet/dotnet-diag

@tommcdon tommcdon self-assigned this Apr 22, 2025
Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

lgtm. we will take for consideration in 9.0.x

@jeffschwMSFT jeffschwMSFT added the Servicing-consider Issue for next servicing release review label Apr 22, 2025
@jeffschwMSFT jeffschwMSFT modified the milestones: 10.0.0, 9.0.x Apr 22, 2025
@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Apr 22, 2025
@leecow leecow modified the milestones: 9.0.x, 9.0.6 Apr 22, 2025
@tommcdon tommcdon merged commit 0eba939 into release/9.0-staging Apr 23, 2025
99 of 104 checks passed
@tommcdon tommcdon deleted the backport/pr-114887-to-release/9.0-staging branch April 23, 2025 00:49
@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.
Labels
area-VM-coreclr Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants