Skip to content

[cDAC] SOS expects deterministic destruction of COM objects #117785

Closed

Description

@max-charlamb

The cDAC SOS tests have intermittently been failing due to non-deterministic destruction of COM objects. SOS releases then immediately frees the DAC library. The was okay with a native COM implementation as the objects are freed as soon as the ref count hits 0. However, this behavior is problematic with a managed COM implementation. The source generated COM implementation used in the cDAC only releases its held references on finalization. While it would be theoretically possible to shim the COM Release call to deterministically release held resources, the manage object would still not be freed deterministically and therefore would cause a memory leak.

Currently we occasionally see the following error in test runs. This is caused by a race condition between the GC and SOS unloading the DAC. The cDAC tries to release its handle to the DAC after the DAC is unloaded leading to an AV.

STDERROR: 00:01.961:    at System.RuntimeExceptionHelpers.FailFast(String, Exception, String, RhFailFastReason, IntPtr, IntPtr) + 0x2b7
STDERROR: 00:01.961:    at System.RuntimeExceptionHelpers.GetRuntimeException(ExceptionIDs) + 0x231
STDERROR: 00:01.962:    at System.Runtime.EH.GetClasslibException(ExceptionIDs, IntPtr) + 0x5d
STDERROR: 00:01.962:    at System.Runtime.InteropServices.Marshal.Release(IntPtr) + 0x46
STDERROR: 00:01.962:    at System.Runtime.InteropServices.Marshalling.FreeThreadedStrategy.System.Runtime.InteropServices.Marshalling.IIUnknownStrategy.Release(Void*) + 0x1c
STDERROR: 00:01.962:    at System.Runtime.InteropServices.Marshalling.DefaultCaching.System.Runtime.InteropServices.Marshalling.IIUnknownCacheStrategy.Clear(IIUnknownStrategy) + 0xf8
STDERROR: 00:01.962:    at System.Runtime.InteropServices.Marshalling.ComObject.Finalize() + 0x59
STDERROR: 00:01.962:    at System.Runtime.__Finalizer.DrainQueue() + 0x8e
STDERROR: 00:01.962:    at System.Runtime.__Finalizer.ProcessFinalizers() + 0x42

Furthermore, NativeAOT DLLs do not support unloading at all. In order to support the cDAC SOS should stop unloading the DAC/cDAC libraries between stop points.

Activity

  1. added
    untriaged
    on Jul 17, 2025
  2. added and removed
    untriaged
    on Jul 17, 2025
  3. dotnet-policy-service commented on Jul 17, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  4. dotnet-policy-service commented on Jul 17, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  5. dotnet-policy-service commented on Jul 17, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  6. dotnet-policy-service commented on Jul 17, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  7. added this to the 11.0.0 milestone on Jul 20, 2025
  8. max-charlamb commented on Jun 30, 2026

    @max-charlamb
    MemberAuthor

    Fixed by dotnet/diagnostics#5586 (merged Dec 2025), which removed FreeLibrary invocations in the managed SOS host. The managed host no longer unloads the DAC/cDAC library, eliminating the race between SOS unload and managed COM finalization. This also aligns with NativeAOT requirements (NativeAOT binaries don't support unloading, #103028).

    Closing.

  9. locked and limited conversation to collaborators on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions