Skip to content

Commit 6cffc15

Browse files
github-actions[bot]Sergio0694jkotas
authored
[release/9.0-staging] Don't wait for finalizers in 'IReferenceTrackerHost::ReleaseDisconnectedReferenceSources' (#110558)
* Do not wait for finalizers on tracker host callbacks * Apply suggestions from PR review * Remove unnecessary try/catch --------- Co-authored-by: Sergio Pedri <[email protected]> Co-authored-by: Jan Kotas <[email protected]>
1 parent 7a95474 commit 6cffc15

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/coreclr/interop/trackerobjectmanager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ namespace
8484

8585
STDMETHODIMP HostServices::ReleaseDisconnectedReferenceSources()
8686
{
87-
return InteropLibImports::WaitForRuntimeFinalizerForExternal();
87+
// We'd like to call InteropLibImports::WaitForRuntimeFinalizerForExternal() here, but this could
88+
// lead to deadlock if the finalizer thread is trying to get back to this thread, because we are
89+
// not pumping anymore. Disable this for now. See: https://github.com/dotnet/runtime/issues/109538.
90+
return S_OK;
8891
}
8992

9093
STDMETHODIMP HostServices::NotifyEndOfReferenceTrackingOnThread()

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,15 +1503,10 @@ internal static unsafe int IReferenceTrackerHost_DisconnectUnusedReferenceSource
15031503
[UnmanagedCallersOnly]
15041504
internal static unsafe int IReferenceTrackerHost_ReleaseDisconnectedReferenceSources(IntPtr pThis)
15051505
{
1506-
try
1507-
{
1508-
GC.WaitForPendingFinalizers();
1509-
return HResults.S_OK;
1510-
}
1511-
catch (Exception e)
1512-
{
1513-
return Marshal.GetHRForException(e);
1514-
}
1506+
// We'd like to call GC.WaitForPendingFinalizers() here, but this could lead to deadlock
1507+
// if the finalizer thread is trying to get back to this thread, because we are not pumping
1508+
// anymore. Disable this for now. See: https://github.com/dotnet/runtime/issues/109538.
1509+
return HResults.S_OK;
15151510
}
15161511

15171512
[UnmanagedCallersOnly]

0 commit comments

Comments
 (0)