Skip to content

time: drop timer lock before dropping waker in clear_entry - #8552

Merged
Darksonn merged 1 commit into
tokio-rs:tokio-1.51.xfrom
Darksonn:f08
Oct 2, 2026
Merged

Darksonn merged 1 commit into
tokio-rs:tokio-1.51.xfrom
Darksonn:f08

Conversation

@Darksonn

@Darksonn Darksonn commented Oct 2, 2026

Copy link
Copy Markdown
Member

When cancelling a timer in Handle::clear_entry, TimerHandle::fire
returns the previously registered Option<Waker>. Previously, that
temporary was dropped before lock went out of scope, running the
waker's destructor while still holding the timer driver mutex. If the
waker's Drop implementation drops or resets another registered Sleep
on the same runtime, it attempts to lock the timer driver mutex again
and deadlocks.

Explicitly drop the driver lock before dropping the returned waker.

Fixes: #8551

When cancelling a timer in `Handle::clear_entry`, `TimerHandle::fire`
returns the previously registered `Option<Waker>`. Previously, that
temporary was dropped before `lock` went out of scope, running the
waker's destructor while still holding the timer driver mutex. If the
waker's `Drop` implementation drops or resets another registered `Sleep`
on the same runtime, it attempts to lock the timer driver mutex again
and deadlocks.

Explicitly drop the driver lock before dropping the returned waker.

Fixes: tokio-rs#8551
@Darksonn Darksonn added C-enhancement Category: A PR with an enhancement or bugfix. A-tokio Area: The main tokio crate M-time Module: tokio/time labels Oct 2, 2026
@Darksonn
Darksonn requested a review from ADD-SP October 2, 2026 13:18
@github-actions github-actions Bot added the R-loom-time-driver Run loom time driver tests on this PR label Oct 2, 2026
@Darksonn Darksonn added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2026
@Darksonn
Darksonn merged commit 24ca445 into tokio-rs:tokio-1.51.x Oct 2, 2026
104 checks passed
@Darksonn
Darksonn deleted the f08 branch October 2, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-time Module: tokio/time R-loom-time-driver Run loom time driver tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants