Skip to content

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 a team and hawkw 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