Skip to content
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

time: panic in release when timer polled after completing #3681

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions tokio/src/time/driver/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,23 @@ impl StateCell {
///
/// SAFETY: Must hold the driver lock.
unsafe fn mark_pending(&self, not_after: u64) -> Result<(), u64> {
// Quick initial debug check to see if the timer is already fired. Since
// firing the timer can only happen with the driver lock held, we know
// we shouldn't be able to "miss" a transition to a fired state, even
// with relaxed ordering.
let mut cur_state = self.state.load(Ordering::Relaxed);

loop {
debug_assert!(cur_state < STATE_MIN_VALUE);
// Check to see if the timer is already fired. Since firing the
// timer can only happen with the driver lock held, we know we
// shouldn't be able to "miss" a transition to a fired state, even
// with relaxed ordering.
//
// In part also to improve the error message for things like
// https://github.com/tokio-rs/tokio/issues/3675
assert!(cur_state < STATE_MIN_VALUE, "timer polled after completing");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right error message here? Can it actually happen if it is polled after completion too, or does this require moving a pinned Sleep?


if cur_state > not_after {
break Err(cur_state);
}

match self.state.compare_exchange(
match self.state.compare_exchange_weak(
cur_state,
STATE_PENDING_FIRE,
Ordering::AcqRel,
Expand Down