Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Crash when disposing an EventListener during shutdown #103480

Copy link
Copy link

Description

@kevingosse
Issue body actions

Description

When there are multiple EventListeners in the same application, disposing one of them during application shutdown causes a crash. It affects at least .NET 6/7/8. Reproduced on Windows and Linux.

Reproduction Steps

Minimal repro:

    public class MyEventListener : EventListener
    {
        public MyEventListener()
        {
            EventSourceCreated += (_, e) => EnableEventSource(e.EventSource);
        }

        private void EnableEventSource(EventSource eventSource)
        {
            EnableEvents(eventSource, EventLevel.Informational, EventKeywords.All);
        }
    }

    internal class Program
    {
        static EventListener listener1;
        static EventListener listener2;

        static async Task Main(string[] args)
        {
            listener1 = new MyEventListener();
            listener2 = new MyEventListener();


            AppDomain.CurrentDomain.ProcessExit += (_, _) => listener1.Dispose();
        }
    }

Expected behavior

The app exits normally.

Actual behavior

The app crashes when exiting:

Fatal error. Internal CLR error. (0x80131506)
   at System.Diagnostics.Tracing.EventPipeInternal.Enable(System.String, System.Diagnostics.Tracing.EventPipeSerializationFormat, UInt32, System.Diagnostics.Tracing.EventPipeProviderConfiguration[])
   at System.Diagnostics.Tracing.EventPipeEventDispatcher.CommitDispatchConfiguration()
   at System.Diagnostics.Tracing.EventPipeEventDispatcher.SendCommand(System.Diagnostics.Tracing.EventListener, System.Diagnostics.Tracing.EventCommand, Boolean, System.Diagnostics.Tracing.EventLevel, System.Diagnostics.Tracing.EventKeywords)
   at System.Diagnostics.Tracing.EventListener.DisableEvents(System.Diagnostics.Tracing.EventSource)
   at System.Diagnostics.Tracing.EventListener.CallDisableEventsIfNecessary(System.Diagnostics.Tracing.EventDispatcher, System.Diagnostics.Tracing.EventSource)
   at System.Diagnostics.Tracing.EventListener.RemoveReferencesToListenerInEventSources(System.Diagnostics.Tracing.EventListener)
   at System.Diagnostics.Tracing.EventListener.Dispose()
   at SimpleApp.Program+<>c.<Main>b__2_0(System.Object, System.EventArgs)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.