Skip to content

Deal with Shutdown issues for EventSource on CoreCLR  #8015

Closed
dotnet/coreclr
#24847

Description

@vancem

The CLR has a general problem with callbacks from managed code on shutdown. The issue is that when the CLR shuts down it tears down EE structures needed to run managed code but it does NOT necessarily call the destructors of managed objects.

This is a problem if you have a native callback (that can happen at any time) because that native code could call that callaback during shutdown when it is illegal to call managed code.

The short term solution is to use the

               AppDomain.CurrentDomain.ProcessExit += DisposeOnShutdown;
                AppDomain.CurrentDomain.DomainUnload += DisposeOnShutdown;

APIs to insure that these callbacks are shut down before CLR shutdown happens. This was done on the Desktop framework but (I think because these events did not exist in Core 1.0 it was pulled from .NET Core. These APIs I believe are back, so we can do this. This issue is a reminder to do this.

The DisposeOnShutdown method is already present in EventSource, so pretty much you just need to put the APIs above back in.


As extra credit, we should consider fixing this in a generic way (this problem is a 'gotcha' that can occur in most uses of native->managed callbacks. Ideally it is fixed in a generic way.

Activity

  1. removed their assignment
    on Mar 22, 2018
  2. transferred this issue fromdotnet/coreclron Jan 31, 2020
  3. added this to the Future milestone on Jan 31, 2020
  4. ghost locked as resolved and limited conversation to collaborators on Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions