dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.91k stars 4.63k forks source link

Exception thrown in GC callback while walking native object wrappers on AOT #104582

Open manodasanW opened 1 month ago

manodasanW commented 1 month ago

Description

Running WinUI Gallery published for AOT using latest WinAppSDK and CsWinRT preview will result in a hang randomly after navigating numerous pages.

Reproduction Steps

WindowsAppSDK: 1.6.240701003-experimental2 CsWinRT: 2.1.0-prerelease.240602.1 WindowsSdkPackageVersion: 10.0.22621.35-preview

Expected behavior

App doesn't hang

Actual behavior

It looks like the app just hangs but debugging it, this is really an exception being thrown on the GC thread. This exception is being thrown because the collection being iterated on got into a bad state and has entries that have been freed but are still in the list. This is the result of a missing lock during removal which happens when running the finalizer as that can race with adding to the list.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8 x64 AOT

Other information

No response

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.