-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fixes hang in WinUI apps published to AOT #104583
Fixes hang in WinUI apps published to AOT #104583
Conversation
…rom and adding to the nativeObjectReference list around the same time and causing removal to fail.
…d to improve performance of remove given it now takes a lock
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
…ads during add / remove.
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Show resolved
Hide resolved
Related: microsoft/microsoft-ui-xaml#9928 |
This seems infeasible at this point. WASDK 1.6 will go GA shortly, and this fix will likely only make it to .NET 9 GA at the earliest. |
What’s a reasonable ETA in months? So that I can drop WinUI for now and go back to UWP, while planning for the next steps. |
@FrayxRulez I don't have an ETA I can state yet as I still need to have a conversation with the .NET folks. But I do have plans on getting the PR feedback addressed very soon so we can then figure that out. |
Is there any conceivable workaround for this, while awaiting a .NET update? |
No. Unfortunately it's a show stopper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10836541436 |
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/10837018960 |
@manodasanW an error occurred while backporting to release/8.0-staging, please check the run log for details! Error: @manodasanW is not a repo collaborator, backporting is not allowed. If you're a collaborator please make sure your dotnet team membership visibility is set to Public on https://github.com/orgs/dotnet/people?query=manodasanW |
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/10838290100 |
@jkoritzinsky backporting to release/8.0-staging failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix exception during GC callback in WinUI scenarios due to removing from and adding to the nativeObjectReference list around the same time and causing removal to fail.
Using index info to reconstruct a base tree...
M src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Applying: Move common logic
Using index info to reconstruct a base tree...
M src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Applying: Change collection type to HashSet to match with JIT implementation and to improve performance of remove given it now takes a lock
Applying: Move to using a custom collection to protect against GC freezing threads during add / remove.
error: sha1 information is lacking or useless (src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0004 Move to using a custom collection to protect against GC freezing threads during add / remove.
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@jkoritzinsky an error occurred while backporting to release/8.0-staging, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
* Fix exception during GC callback in WinUI scenarios due to removing from and adding to the nativeObjectReference list around the same time and causing removal to fail. * Move common logic * Change collection type to HashSet to match with JIT implementation and to improve performance of remove given it now takes a lock * Move to using a custom collection to protect against GC freezing threads during add / remove. * Address PR feedback by using alternative approach to handle race * Address PR feedback * Address PR feedback around handle being freed.
* Fix exception during GC callback in WinUI scenarios due to removing from and adding to the nativeObjectReference list around the same time and causing removal to fail. * Move common logic * Change collection type to HashSet to match with JIT implementation and to improve performance of remove given it now takes a lock * Move to using a custom collection to protect against GC freezing threads during add / remove. * Address PR feedback by using alternative approach to handle race * Address PR feedback * Address PR feedback around handle being freed.
Is this fix already available in either .NET 9 or .NET 8? |
No. It will be available in .NET 9 RC2. |
* Fix exception during GC callback in WinUI scenarios due to removing from and adding to the nativeObjectReference list around the same time and causing removal to fail. * Move common logic * Change collection type to HashSet to match with JIT implementation and to improve performance of remove given it now takes a lock * Move to using a custom collection to protect against GC freezing threads during add / remove. * Address PR feedback by using alternative approach to handle race * Address PR feedback * Address PR feedback around handle being freed.
In the AOT version of
ComWrappers
, we keep track of thenative object wrappers
that implementIReferenceTracker
and iterate on them during GC callbacks as part of the reference walk. We were running into scenarios whereGCHandles
in that collection were already freed but are still in the collection and thereby causing unexpected exceptions. This looks to be the result of a race that is happening when we are removing from that collection and adding to it as the removal has no locking at all around it and is failing randomly. The adding to the collection does have some locking, but that locking is for another cache and isn't consistent everywhere we add to it. This change adds a lock which is used during interactions with that collection. The lock is not used during the GC callback scenarios as the threads would be frozen already and we can end up in a scenario where the lock is already being held.Given we are now doing locking during removal in the finalizer, I am also updating the collection type to a
HashSet
rather than aList
. This makes it consistent with what we do in the JIT version of this implementation and also looking at some brief traces ofWinUIGallery
in both scenarios, there is definitely an improvement seen during removal with theHashSet
approach while not much additional cost when adding it or iterating over it.Fixes #104582