From 24344dfe4b69931bfe9fe686d2424c9f626dc75b Mon Sep 17 00:00:00 2001 From: Weijia Jiang Date: Tue, 16 Jul 2024 21:25:59 +0800 Subject: [PATCH 1/2] time: fix race condition leading to lost timers (#6683) --- tokio/src/runtime/time/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tokio/src/runtime/time/mod.rs b/tokio/src/runtime/time/mod.rs index 37b04ef00..c01a5f2b2 100644 --- a/tokio/src/runtime/time/mod.rs +++ b/tokio/src/runtime/time/mod.rs @@ -190,11 +190,13 @@ impl Driver { assert!(!handle.is_shutdown()); // Finds out the min expiration time to park. - let expiration_time = (0..rt_handle.time().inner.get_shard_size()) - .filter_map(|id| { - let lock = rt_handle.time().inner.lock_sharded_wheel(id); - lock.next_expiration_time() - }) + let locks = (0..rt_handle.time().inner.get_shard_size()) + .map(|id| rt_handle.time().inner.lock_sharded_wheel(id)) + .collect::>(); + + let expiration_time = locks + .iter() + .filter_map(|lock| lock.next_expiration_time()) .min(); rt_handle @@ -203,6 +205,9 @@ impl Driver { .next_wake .store(next_wake_time(expiration_time)); + // Safety: After updating the `next_wake`, we drop all the locks. + drop(locks); + match expiration_time { Some(when) => { let now = handle.time_source.now(rt_handle.clock()); From 14b9f7115728b77c82db8d21b6d768d16dc472a6 Mon Sep 17 00:00:00 2001 From: Weijia Jiang Date: Tue, 16 Jul 2024 23:16:29 +0800 Subject: [PATCH 2/2] chore: release Tokio v1.38.1 (#6688) --- README.md | 2 +- tokio/CHANGELOG.md | 12 ++++++++++++ tokio/Cargo.toml | 2 +- tokio/README.md | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b9d9eb785..6a3d0e2be 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.38.0", features = ["full"] } +tokio = { version = "1.38.1", features = ["full"] } ``` Then, on your main.rs: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index acd3bacd5..cfe70fa4d 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -1,3 +1,15 @@ +# 1.38.1 (July 16th, 2024) + +This release fixes the bug identified as ([#6682]), which caused timers not +to fire when they should. + +### Fixed + +- time: update `wake_up` while holding all the locks of sharded time wheels ([#6683]) + +[#6682]: https://github.com/tokio-rs/tokio/pull/6682 +[#6683]: https://github.com/tokio-rs/tokio/pull/6683 + # 1.38.0 (May 30th, 2024) This release marks the beginning of stabilization for runtime metrics. It diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index ac7595153..13a9a8c05 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio" # - README.md # - Update CHANGELOG.md. # - Create "v1.x.y" git tag. -version = "1.38.0" +version = "1.38.1" edition = "2021" rust-version = "1.63" authors = ["Tokio Contributors "] diff --git a/tokio/README.md b/tokio/README.md index b9d9eb785..6a3d0e2be 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.38.0", features = ["full"] } +tokio = { version = "1.38.1", features = ["full"] } ``` Then, on your main.rs: