Skip to content

[Tracing] EventProvider Disposal hangs within a callback #106087

Open
@mdh1418

Description

@mdh1418

Description

#80666 uncovered an issue where EventPipeEventProvider's callback had been invoked after the gchandle was freed. To align EventPipe with ETW which blocks disposal for in-flight callbacks, #106040 added a signal wait/set blocking behavior to ep_delete_provider. As a result, a deadlock can occur should users invoke EventPipeEventProvider's Unregister or ep_delete_provider within a callback.

The same behavior is exhibited on ETW

Reproduction Steps

using System.Diagnostics.Tracing;

MyEventSource eventSource = new MyEventSource();
Console.WriteLine("MyEventSource is ready to be enabled");
Console.ReadLine();

[EventSource(Name ="MyEventSource")]
class MyEventSource : EventSource
{
    override protected void OnEventCommand(EventCommandEventArgs command)
    {
        Console.WriteLine($"Command: {command.Command}");
        this.Dispose();
        Console.WriteLine($"Dispose() complete");
    }
}

dotnet-trace collect --providers MyEventSource -p <pid of running sample>

Expected behavior

Sample's output

MyEventSource is ready to be enabled
Command: Enable
Dispose() complete

Actual behavior

Sample's output

MyEventSource is ready to be enabled
Command: Enable

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions