[release/9.0-staging] Fix debugger app hangs related to thread exit #114917
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.
Backport of #114887 to release/9.0-staging
/cc @tommcdon
Customer Impact
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
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
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