Skip to content

Early init for FrameworkEventSource#126737

Merged
noahfalk merged 1 commit intodotnet:mainfrom
noahfalk:init_framework_eventsource
Apr 10, 2026
Merged

Early init for FrameworkEventSource#126737
noahfalk merged 1 commit intodotnet:mainfrom
noahfalk:init_framework_eventsource

Conversation

@noahfalk
Copy link
Copy Markdown
Member

ThreadPoolWorkQueue uses FrameworkEventSource during ThreadPool initialization. If that is the first time the FrameworkEventSource is being used, creating it on-demand will acquire the EventListener lock which can deadlock. We avoid that deadlock by creating the EventSource earlier on the startup path where nothing is waiting and holding the lock.

We've seen several of these EventSource lock deadlocks over the years and it would be nice to make a more comprehensive fix, but unforetunately the only broad fix I know of would be make EventSource callbacks asynchronous relative to the underlying ETW callbacks. That isn't out of the question but it does carry a broader set of compatibility risks so we've generally favored these lower risk spot fixes instead.

Fixes #126591

ThreadPoolWorkQueue uses FrameworkEventSource during ThreadPool initialization. If that is the first time
the FrameworkEventSource is being used, creating it on-demand will acquire the EventListener lock which can deadlock.
We avoid that deadlock by creating the EventSource earlier on the startup path where nothing is waiting and holding the
lock.

We've seen several of these EventSource lock deadlocks over the years and it would be nice to make a more comprehensive fix, but
unforetunately the only broad fix I know of would be make EventSource callbacks asynchronous relative to the underlying ETW
callbacks. That isn't out of the question but it does carry a broader set of compatibility risks so we've generally favored these lower
risk spot fixes instead.

Fixes dotnet#126591
Copilot AI review requested due to automatic review settings April 10, 2026 00:48
@noahfalk
Copy link
Copy Markdown
Member Author

noahfalk commented Apr 10, 2026

@dotnet/dotnet-diag
@tarekgh

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Pre-initializes FrameworkEventSource during the runtime’s default EventSource initialization to avoid an on-demand EventSource creation path that can take EventListener.EventListenersLock during ThreadPool startup and contribute to the deadlock described in #126591.

Changes:

  • Create FrameworkEventSource eagerly in EventSource.InitializeDefaultEventSources() under FEATURE_PERFTRACING.
  • Add inline rationale/comment referencing the deadlock scenario and linked issue.

@tarekgh tarekgh added this to the 11.0.0 milestone Apr 10, 2026
Copy link
Copy Markdown
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@noahfalk noahfalk merged commit ce3e716 into dotnet:main Apr 10, 2026
155 of 158 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadlock when handling EventCommand.Disable in MetricsEventSource (.NET 10)

3 participants