Repository navigation
Narrow active_sessions_mutex_ scope around ETW callback registration - #32000
Merged
Merged
Conversation
InferenceSession's constructor and destructor held active_sessions_mutex_ while calling into the telemetry and ETW sink callback registries, each of which takes its own registry lock. The ETW dispatch path acquires those locks in the opposite order: a capture-state notification runs the registered callback under the registry lock, and that callback reaches LogAllSessions, which takes active_sessions_mutex_. Two threads hitting these paths concurrently can form a lock cycle and hang the process. Register and unregister the callbacks outside the active_sessions_mutex_ critical section so the two locks are never held at once. The registries are independently synchronized and do not require active_sessions_mutex_. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Akshay Sonawane (apsonawane)
requested review from
Tianlei Wu (tianleiwu)
and
a lite review from Copilot
August 11, 2026 23:24
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 11, 2026 23:24
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts InferenceSession ETW callback registration/unregistration on Windows to avoid a lock-order inversion between active_sessions_mutex_ and the ETW/telemetry callback registry locks, preventing potential deadlocks during ETW dispatch and session lifecycle events.
Changes:
- Narrows the
active_sessions_mutex_critical section inConstructorCommonso it isnβt held across ETW callback registration. - Updates teardown logic to avoid holding
active_sessions_mutex_while unregistering ETW callbacks.
π‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InferenceSession's constructor and destructor held active_sessions_mutex_ while calling into the telemetry and ETW sink callback registries, each of which takes its own registry lock. The ETW dispatch path acquires those locks in the opposite order: a capture-state notification runs the registered callback under the registry lock, and that callback reaches LogAllSessions, which takes active_sessions_mutex_. Two threads hitting these paths concurrently can form a lock cycle and hang the process.
Register and unregister the callbacks outside the active_sessions_mutex_ critical section so the two locks are never held at once. The registries are independently synchronized and do not require active_sessions_mutex_.