Fix frequent FuncEval abort upon hitting a breakpoint in an ASP.NET Core web app...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fri, 27 Aug 2021 13:52:28 +0000 (06:52 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Aug 2021 13:52:28 +0000 (06:52 -0700)
commitbb952dbc846acaaf915a9e6b55603561fb882f0d
tree28b4e31e77a9144f22a5f39322bb69eb82804853
parent824368bb974f36c02bde63bc90710c0c11ee1437
Fix frequent FuncEval abort upon hitting a breakpoint in an ASP.NET Core web app (#58218)

- `AssemblySpecBindingCache` uses a cooperative-GC-mode data structure for the cache and operates on the cache from inside a lock taken in preemptive-GC-mode
- So when the cache is being used, cooperative-GC-mode is entered while holding the lock, which can in turn suspend for the debugger. Then a FuncEval that also happens to operate on the cache would deadlock on acquiring the lock and would have to be aborted.
- This seems to be happening very frequently when hitting an early breakpoint in a default new ASP.NET Core web app in .NET 6 when hot reload is enabled
- Fixed by using the same solution that was used for the slot backpatching lock. When cooperative-GC-mode would be entered inside the lock, a different lock holder based on `CrstAndForbidSuspendForDebuggerHolder` is used, which prevents the thread from suspending for the debugger while the lock is held. The thread would instead suspend for the debugger after leaving the forbid region after releasing the lock.

Co-authored-by: Koundinya Veluri <kouvel@microsoft.com>
src/coreclr/vm/appdomain.cpp
src/coreclr/vm/appdomain.hpp
src/coreclr/vm/crst.cpp