Repository navigation
Description
Description
I've had two spurious EEE's pop out at me while I was in the debugger over the last week, working on the new version of my app (Paint.NET v5.1) that is targeting .NET 8. I was worried it was due to my new code, some of which is clipboard related (always a bug farm) ...
... But I'm now able to reproduce this 100% with my latest public release (Paint.NET v5.0.11, .NET 7.0.12), when it's retargeted for .NET 8. It has no trouble with .NET 7.
I believe this is a new bug in .NET 8, it's not due to any changes I've made in my code.
Reproduction Steps
You will need access to https://github.com/dotnet/paint.net/ -- just ask and I will add you (for MSFT employees that is)
You will want this branch: https://github.com/dotnet/paint.net/tree/net8_EEE_repro . This is branched from v5.0.11, the latest public release using .NET 7, and then I've done the minimal amount of work to get it running on .NET 8 rc2 (mostly some nullable fixes that are already in my newer v5.1 branch)
- You must have long file paths enabled for Windows, which may require a reboot, due to some source generators that end up using super long paths https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
- Load up ./paintdotnet.sln in Visual Studio 2022 17.8.0 Preview 7.0.
- Due to something I haven't quite yet figured out with respect to project dependencies, you will first have to manually rebuild the AppVersion project. It's at Solution Explorer -> Misc (the first node) -> AppVersion
- Now do a full rebuild
- Verify that the
DOTNET_GCStress=2environment variable is set up in the Debug properties - Debug menu -> Start Debugging
- You will eventually (~20-60 seconds) see an
ExecutionEngineExceptionpop up before the app's main window is displayed
Expected behavior
App starts up just fine, albeit very slowly due to DOTNET_GCStress=2
Actual behavior
App is not able to initialize, it dies with an EEE before the main window is displayed. On my system it's usually somewhere in the constructor for the FileMenu class, but there's some random variance as to exactly where it dies.
It usually won't even show a callstack in the debugger, and when it does it will not load symbols for the relevant .NET framework/runtime DLLs:
Regression?
Yes. This works fine if you change ./paintdotnet/paintdotnet.csproj to target .NET 7. Just remove the <TargetFramework> element at the top and do a full rebuild (sometimes need to do that twice after changing TargetFramework, as the first time will error due to what I think is a VS or msbuild bug). It will then revert to .NET 7 based on the values in ./TargetFramework.props
Known Workarounds
No response
Configuration
Visual Studio 2022 17.8.0 Preview 7.0
x64
.NET 8 RC2
Happens on both my desktop:
Ryzen 9 7950X
Windows 11 23H2 build 22635.2700
and on my Lenovo P16 laptop:
Intel Core i7-12800HX
Windows 11 23H2 build 22631.2506
Other information
cc @EgorBo who was commenting on this a little over on Discord, and who already has access to the dotnet/paint.net repository. Also @MichalPetryka who recommended me to file the issue
Activity
mangod9 commentedon Nov 9, 2023
the fact that it repros with GCStress indicates its some heap corruption, so possibly something the WinForms team should initially investigate. Is it easy to share a few dumps?
rickbrew commentedon Nov 9, 2023
Sure; just via Task Manager's right click -> Create memory dump file?
rickbrew commentedon Nov 10, 2023
Here is a DMP file from the paintdotnet.exe process right when it crashed: https://1drv.ms/u/s!Ak4YjacO2C9yktlxwjC_frr4DNymkA?e=5JChdi
Let me know when you have the file so I can un-share/delete it
mangod9 commentedon Nov 10, 2023
As I had suspected the heap seems to be corrupted. Please provide access to the repo, so we can try to repro locally. Alternatively perhaps you could run with
COMPLUS_HeapVerify=1and share some dumps.mangod9 commentedon Nov 10, 2023
Also adding @AaronRobinsonMSFT since there is
ComAwareWeakReferenceon the stack. Not sure if there have been any recent changes in this space.AaronRobinsonMSFT commentedon Nov 11, 2023
@VSadov Did change the weak reference logic to be mostly managed last year - see #77196. Since this is failing in the weak reference logic specifically, I think that is likely the best place to start.
9 remaining items
AaronRobinsonMSFT commentedon Nov 12, 2023
Why not make them precious? This back and forth seems less than ideal.
VSadov commentedon Nov 12, 2023
Some early-2000 Java VMs experimented with lock-deflation. If a fat lock becomes uncontended, you may try to reduce it back into a thin lock when GC runs. It is however rare that locks change their habits permanently. Once deflated, the lock will likely inflate again. I am not aware if any modern VM does this.
The code in question looks like an attempt to do something similar, but it does not go all the way. It would not deflate a fully inflated lock. It only deflates if it catches a lock in an intermediate stage - when there is a syncblock, but no OS event allocated yet. That is probably why it is rare to see the effects outside of GC stress.
There is also a piece that does not allow thin lock acquires if GC wants to happen, which is nearly always the case under GC stress. That leads to locks inflating even if there is no contention and creates an artificial opportunity for the above "optimization" to happen.
The code could use some clean up, but not in a servicing fix that we'd like to port to 8.0
jkotas commentedon Nov 12, 2023
Reopening for backport
teo-tsirpanis commentedon Jan 15, 2024
This has been backported to .NET 8.0.1.