Skip to content

fix(tracing-core): prevent potential deadlock by retaining Dispatch instances until after lock is released #3275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v0.1.x
Choose a base branch
from

Conversation

u-kai
Copy link

@u-kai u-kai commented May 11, 2025

Motivation

Dropping Dispatch instances during a call to register_callsite can result in a deadlock.

This occurs when a Dispatch's associated Subscriber implementation performs logging (e.g., via info!) in its Drop implementation.
Since info! internally triggers register_callsite, this can re-enter the same lock (LOCKED_DISPATCHERS) already held during interest rebuilding, causing a deadlock.

This PR addresses Issue #3269, which provides a minimal example of the issue.

Solution

This PR introduces a temporary DispatchGuard (a Vec<Dispatch>) to retain strong references to Dispatch instances during the for_each traversal used in interest rebuilding.

By ensuring that these Dispatch instances are dropped only after the write lock on LOCKED_DISPATCHERS has been released,
we prevent re-entrant locking in the Drop path of a Subscriber, avoiding the deadlock.

…nstances until after lock is released

Signed-off-by: u-kai <[email protected]>
@u-kai u-kai requested review from hawkw and a team as code owners May 11, 2025 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant