Closed masloboev closed 2 months ago
@mdh1418
I've run into this problem as well. Is there an acceptable workaround?
So far I've tried manually disposing of the System.Runtime trace source in the Main method like this:
var sources = EventSource.GetSources();
var runtime = sources.FirstOrDefault(x => x.Name == "System.Runtime");
runtime?.Dispose();
This worked but I don't know if it will have any unintended consequences.
I believe this is fixed by https://github.com/dotnet/runtime/pull/105548. I was able to repro the issue on .NET Sdk 8.0.300, and using a local build of runtime with the PR I could not trigger the deadlock.
Description
Deadlock in System.Diagnostics.Tracing.FrameworkEventSource on “System.Runtime” event pipe provider initialization. Deadlock occurs when counters are requested on application startup between these two objects: EventListener.EventListenersLock monitor lock and System.Diagnostics.Tracing.FrameworkEventSource type access critical section.
Deadlock description
Thread 1:
This can come from any point that checks FrameworkEventSource.Log.IsEnabled. In the attached dump it is checked for ThreadTransfer event.
Thread 2:
But the type FrameworkEventSource is still not initialized.
Full stack traces
Thread 1:
Thread 2:
Reproduction Steps
Connect EventPipe with enabled "System.Runtime" provider to application on application startup.
Deadlock dump reference: dump
Expected behavior
Event pipe is connected, EventCounters events are sending
Actual behavior
Application hangs, deadlock occured
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8.0.524.21615 (dotnet-sdk-8.0.300-win-x64-d1497a0e) OS Windows 10 x64 no, it is not specific to this configuration
Other information
This issue prevents using “System.Runtime” events provider for .NET Core applications moniotring
Solutions: Maybe postpone or pull out from under the lock counters initialization (System.Diagnostics.Tracing.CounterGroup.ResetCounters) is good solution. Another solution is warm up FrameworkEventSource before counters initialization.
Similar issue: ThreadPoolWorkQueue..ctor randomly will never return