Skip to content

Commit

Permalink
Merge branch 'master' into timeout-lazy-init-sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Apr 26, 2024
2 parents 8e40ec4 + d33fdd8 commit d328298
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 5 additions & 5 deletions tokio/src/runtime/task/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ where
}

pub(super) fn dealloc(self) {
// Release the join waker, if there is one.
self.trailer().waker.with_mut(drop);

// Check causality
self.core().stage.with_mut(drop);
// Observe that we expect to have mutable access to these objects
// because we are going to drop them. This only matters when running
// under loom.
self.trailer().waker.with_mut(|_| ());
self.core().stage.with_mut(|_| ());

// Safety: The caller of this method just transitioned our ref-count to
// zero, so it is our responsibility to release the allocation.
Expand Down
4 changes: 3 additions & 1 deletion tokio/src/time/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ impl Interval {
self.missed_tick_behavior
.next_timeout(timeout, now, self.period)
} else {
timeout + self.period
timeout
.checked_add(self.period)
.unwrap_or_else(Instant::far_future)
};

// When we arrive here, the internal delay returned `Poll::Ready`.
Expand Down
8 changes: 7 additions & 1 deletion tokio/tests/time_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::task::{Context, Poll};

use futures::{Stream, StreamExt};
use tokio::time::{self, Duration, Instant, Interval, MissedTickBehavior};
use tokio_test::{assert_pending, assert_ready_eq, task};
use tokio_test::{assert_pending, assert_ready, assert_ready_eq, task};

// Takes the `Interval` task, `start` variable, and optional time deltas
// For each time delta, it polls the `Interval` and asserts that the result is
Expand Down Expand Up @@ -469,3 +469,9 @@ async fn stream_with_interval_poll_tick_no_waking() {
// task when returning `Poll::Ready`.
assert_eq!(items, vec![]);
}

#[tokio::test(start_paused = true)]
async fn interval_doesnt_panic_max_duration_when_polling() {
let mut timer = task::spawn(time::interval(Duration::MAX));
assert_ready!(timer.enter(|cx, mut timer| timer.poll_tick(cx)));
}

0 comments on commit d328298

Please sign in to comment.