-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
m_UnresolvedClassLock is held in an unsafe way for Func Evals #60565
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
What is "m_unresolvedClassLock"? Can you point to the code you're referring to in the repo? I don't see that name anywhere in dotnet/runtime. EDIT: I see, casing was wrong. |
The issue is at heart the same as what was fixed here: #58218 |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsDescriptionm_UnresolvedClassLock can be held when an application is in break state. If a func eval triggers an assembly load while that lock is held on another thread the func eval must be aborted. Reproduction StepsSee the following VS feedback ticket: https://developercommunity.visualstudio.com/t/VS2022-preview-41---debugger-message-T/1548980. Expected behaviorA func eval should be able to load an assembly without encountering the effective deadlock with m_unresolvedClassLock. Actual behaviorFunc evals can effectively deadlock and the application ends up in a bad state. Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
This same issue locking issue also looks like it applies to "m_PinnedHeapHandleTableCrst" in "BaseDomain::AllocateObjRefPtrsInLargeTable". |
Is there any idea on a fix? As this has been stale for some time now. I am also experiencing this error and it's making debugging quite a pain. |
Looks like this is related to the hot reload feature. For me the error disappeared after disabling hot reload... |
Same, this behavior ceases for me when hot reload is disabled. Nice find @schwarzr ! Pretty consistent when enabled, even in simple .NET 6 console app. Using latest VS 2022. |
Also getting this - was this fixed in 6.0.1 by any chance? This bug makes Hot Reload (and also Edit and Continue) pretty useless (or annoying at least)... |
I hit it quite often 😢 |
Unfortunately, I have also had this experience 😢. |
If JetBrains Resharper is installed - it tries to show all locals automatically inside the editor inline during debug break, so this issue is reproduced with every second run for me, when I disabled that feature in Resharper - it gone away. |
For me it happens without ReSharper installed. I'm happy it resolved the issue for you, but I'm still experiencing it, which made me switch back to .Net 5 |
Any update on this? I've been running into this constantly. If I turn off hot reload I no longer have the issue but hot reload/edit and continue are pretty essential. |
Same here. Resharper isnt installed aswell. |
Same here. This is quite annoying. I turned off hot reload and Edit&Continue as this feature wasn't working properly (at least with Blazor Server) anyway. |
@noahfalk to see updates above. |
Console app, debug mode with break point. Get the error on the first line of execution after stepping over (F10). Disabling "Edit and continue hot reload" makes the error go away. |
Thanks for sharing that this issue reproduces with console apps and a workaround @nicklasjepsen. This should help us construct a repro to help us understand and develop potential fixes for it. |
Some research into the m_UnresolvedClassLock suggests that this specific cause of the issue was probably resolved when this code was changed early in .NET 7. This doesn't guarantee that all causes of the issue are resolved, or that everyone observing that func-eval abort message was hitting this specific cause, but it should at least mean the situation is improved in .NET 7. Has anyone reproducing the issue on .NET 6 been able to try a .NET 7 preview build to see if the issue is resolved for you? If you can still reproduce it on a .NET 7 preview I'd love to get some dumps from you to try and diagnose any additional variations of this problem. I tried reproducing the problem as described by @nicklasjepsen but I wasn't able to observe any issue. Here is what I did specifically in case anyone has an alternate suggestion of what I should try?
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
I also tried variations where I made edits before hitting F10, did multiple steps, used set next statement, and I changed the project from console app to asp.net core app. None of those variations produced any errors for me.
@auott - in order for someone on the runtime to investigate we either need callstacks where you observed the threads blocked or dumps from debuggee. Do you have them? |
@auott - actually looking at m_PinnedHeapHandleTableCrst this is probably simple enough that I can guess what the repro is even if you don't have stacks. They'd still be handy if you have them though. |
@noahfalk - I don't have any stacks at this point. I also haven't seen any repros that have come from .NET 7 (at least for this specific one) so it's definitely possible some of this has been cleaned up. |
Fixes dotnet#60565 Visual Studio devs reported that debugger funcevals were deadlocking because the PinnedHeapHandleTableCrst was held while threads were suspended. This change refactors that code path so that the AllocateHandles() operation where the lock is held gets split into potentially multiple iterations and the GC allocation where the debugger could suspend is extracted outside the region where the critical section is held. There is another path into AllocateHandles that takes a different lock and theoretically it could generate a similar deadlock, but I didn't do all the refactoring necessary to prevent that path.
I just put up a PR that should resolve the PinnedHeapHandleTableCrst part of the issue. With no known repro I can't guarantee it fixes the problem, but I think I have a decent guess what happened and I am able to use the debugger to confirm that the new debugger suspension point is outside the PinnedHeapHandleTableCrst lock. I am planning to mark the bug resolved once that fix gets checked in and if there are new func-eval deadlocks we can file those as new issues and evaluate them case by case. The runtime has never provided a guarantee that it is safe to run arbitrary func-evals when stopped at arbitrary places, but pragmatically we'll try to resolve any common obstacles if we can. |
Fixes #60565 Visual Studio devs reported that debugger funcevals were deadlocking because the PinnedHeapHandleTableCrst was held while threads were suspended. This change refactors that code path so that the AllocateHandles() operation where the lock is held gets split into two parts and the GC allocation where the debugger could suspend is outside the region where the critical section is held. In the old code the PinnedHeapHandleTable was synchronized by one of two different locks, either the AppDomainHandleTable lock or the GlobalStringLiteralMap. In the new code AppDomainHandleTable lock is renamed to PinnedHeapHandleTable lock and this lock is always what synchronizes the PinnedHeapHandleTable code. In the string literal code path the GlobalStringLiteralMap is taken first and the PinnedHeapHandleTable lock is taken second, but the PinnedHeapHandleTable is no longer reliant on that outer GlobalStringLiteralMap lock for correctness. In terms of testing I can verify under a debugger that I can suspend in the GC allocation point and the PinnedHeapHandleTable lock isn't held. This doesn't of course prevent other locks from being held so at best it is a partial fix for the issue. Nobody had a known repro so I wasn't able to verify anything more specifically. I also confirmed the race cases on the InterlockedExchange paths worked how they were intended by forcing them with a native debugger.
Description
m_UnresolvedClassLock can be held when an application is in break state. If a func eval triggers an assembly load while that lock is held on another thread the func eval must be aborted.
Reproduction Steps
See the following VS feedback ticket: https://developercommunity.visualstudio.com/t/VS2022-preview-41---debugger-message-T/1548980.
Expected behavior
A func eval should be able to load an assembly without encountering the effective deadlock with m_unresolvedClassLock.
Actual behavior
Func evals can effectively deadlock and the application ends up in a bad state.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: