From eacb98e18901fcbe011bfceddbc31853f1bf0c27 Mon Sep 17 00:00:00 2001 From: Amey Pawar <138877912+ameyypawar@users.noreply.github.com> Date: Thu, 16 Jul 2026 16:46:47 +0530 Subject: [PATCH 1/4] runtime: don't skip the driver when `before_park` schedules work (#8222) --- .../runtime/scheduler/current_thread/mod.rs | 11 +++- tokio/tests/rt_common_before_park.rs | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/tokio/src/runtime/scheduler/current_thread/mod.rs b/tokio/src/runtime/scheduler/current_thread/mod.rs index f0b072d57..db8e273eb 100644 --- a/tokio/src/runtime/scheduler/current_thread/mod.rs +++ b/tokio/src/runtime/scheduler/current_thread/mod.rs @@ -385,8 +385,6 @@ impl Context { core = c; } - // If `before_park` spawns a task (or otherwise schedules work for us), then we should not - // park the thread. if !self.has_pending_work(&core) { // Park until the thread is signaled core.metrics.about_to_park(); @@ -396,6 +394,15 @@ impl Context { core.metrics.unparked(); core.submit_metrics(handle); + } else { + // `before_park` scheduled work (e.g. an `on_thread_park` hook that woke the + // `block_on` future), so we don't block. We must still poll the driver once + // without blocking, or timer and I/O events would stall under a runtime driven + // by repeated short `block_on` calls. See + // . + core.submit_metrics(handle); + + core = self.park_internal(core, handle, &mut driver, Some(Duration::from_millis(0))); } if let Some(f) = &handle.shared.config.after_unpark { diff --git a/tokio/tests/rt_common_before_park.rs b/tokio/tests/rt_common_before_park.rs index cb0dc152b..74a281632 100644 --- a/tokio/tests/rt_common_before_park.rs +++ b/tokio/tests/rt_common_before_park.rs @@ -4,6 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::time::Duration; use tokio::runtime::Builder; use tokio::sync::Notify; @@ -90,3 +91,52 @@ fn wake_from_other_thread_block_on() { th.join().unwrap(); } + +// Regression test for #8212: a current-thread runtime driven by repeated short +// `block_on` calls, where `on_thread_park` wakes the `block_on` future, must +// still drive the time driver so a spawned timer keeps making progress. Before +// the fix, `before_park` setting the `woken` flag caused `park` to skip the +// driver entirely, so the timer never fired. +#[test] +fn before_park_does_not_stall_spawned_timer() { + let notify = Arc::new(Notify::new()); + let task_done = Arc::new(AtomicBool::new(false)); + + let rt = Builder::new_current_thread() + .enable_all() + .on_thread_park({ + let notify = notify.clone(); + move || notify.notify_waiters() + }) + .build() + .unwrap(); + + rt.spawn({ + let task_done = task_done.clone(); + async move { + tokio::time::sleep(Duration::from_millis(1)).await; + task_done.store(true, Ordering::SeqCst); + } + }); + + // A current-thread runtime only runs tasks while inside `block_on`, so drive it + // once to let the spawned task register its timer. + rt.block_on(tokio::task::yield_now()); + + // Drive the runtime in short bursts, the way an external event loop would. Each + // burst parks via `on_thread_park` (which wakes the `block_on` future); the fix + // keeps polling the driver so the spawned timer still fires. A regression stalls + // the timer, failing the assert below instead of hanging. + for _ in 0..100 { + if task_done.load(Ordering::SeqCst) { + break; + } + rt.block_on(notify.notified()); + std::thread::sleep(Duration::from_millis(1)); + } + + assert!( + task_done.load(Ordering::SeqCst), + "spawned task's timer never fired (issue #8212)" + ); +} From f84b209126a9b0f66dae1025e30e44d217205513 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 16 Jul 2026 13:59:24 +0200 Subject: [PATCH 2/4] chore: prepare Tokio v1.51.4 (#8286) --- README.md | 2 +- tokio/CHANGELOG.md | 8 ++++++++ tokio/Cargo.toml | 2 +- tokio/README.md | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 58053042d..12574b8b4 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Make sure you enable the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.51.3", features = ["full"] } +tokio = { version = "1.51.4", features = ["full"] } ``` Then, on your main.rs: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index f641577f2..c83a1f2ed 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -1,3 +1,11 @@ +# 1.51.4 (July 16th, 2026) + +### Fixed + +- runtime: don't skip the driver when `before_park` schedules work ([#8222]) + +[#8222]: https://github.com/tokio-rs/tokio/pull/8222 + # 1.51.3 (May 8th, 2026) ### Fixed diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 6652b7621..19c16278a 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.51.3" +version = "1.51.4" edition = "2021" rust-version = "1.71" authors = ["Tokio Contributors "] diff --git a/tokio/README.md b/tokio/README.md index 58053042d..12574b8b4 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -60,7 +60,7 @@ Make sure you enable the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.51.3", features = ["full"] } +tokio = { version = "1.51.4", features = ["full"] } ``` Then, on your main.rs: From 7bcd2d343d997a658be5bc165520070c997fefbc Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Fri, 10 Jul 2026 12:09:45 +0200 Subject: [PATCH 3/4] taskdump: remove crate disambiguators from output (#8288) --- tokio/src/runtime/task/trace/symbol.rs | 3 ++- tokio/tests/task_trace_self.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tokio/src/runtime/task/trace/symbol.rs b/tokio/src/runtime/task/trace/symbol.rs index 49d7ba37f..9dd2ad4b9 100644 --- a/tokio/src/runtime/task/trace/symbol.rs +++ b/tokio/src/runtime/task/trace/symbol.rs @@ -65,7 +65,8 @@ impl Eq for Symbol {} impl fmt::Display for Symbol { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(name) = self.symbol.name() { - let name = name.to_string(); + // Printing this using :# formatting omits crate disambiguators. + let name = format!("{name:#}"); let name = if let Some((name, _)) = name.rsplit_once("::") { name } else { diff --git a/tokio/tests/task_trace_self.rs b/tokio/tests/task_trace_self.rs index e3e0c4791..28a81fff7 100644 --- a/tokio/tests/task_trace_self.rs +++ b/tokio/tests/task_trace_self.rs @@ -138,7 +138,7 @@ fn trace_leaf_for_test(meta: &TraceMeta, log: &mut Vec>) { for frame in bt.frames() { for symbol in frame.symbols() { if let Some(name) = symbol.name() { - names.push(strip_symbol_hash(&format!("{name}")).to_owned()); + names.push(strip_symbol_hash(&format!("{name:#}")).to_owned()); } } } From efdba5fcf02c4b93d379114df136b994c3b21445 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 16 Jul 2026 15:23:48 +0200 Subject: [PATCH 4/4] chore: prepare Tokio v1.52.4 (#8289) --- 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 01e7a84f6..2f70d84bd 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Make sure you enable the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.52.3", features = ["full"] } +tokio = { version = "1.52.4", features = ["full"] } ``` Then, on your main.rs: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index 75500a0da..6f0e19343 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -1,3 +1,15 @@ +# 1.52.4 (July 16th, 2026) + +### Fixed + +- runtime: don't skip the driver when `before_park` schedules work ([#8222]) + +### Fixed (unstable) + +- taskdump: remove crate disambiguators from output ([#8264]) + +[#8264]: https://github.com/tokio-rs/tokio/pull/8264 + # 1.52.3 (May 8th, 2026) ### Fixed diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 123781bbf..a4d876f52 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.52.3" +version = "1.52.4" edition = "2021" rust-version = "1.71" authors = ["Tokio Contributors "] diff --git a/tokio/README.md b/tokio/README.md index 01e7a84f6..2f70d84bd 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -60,7 +60,7 @@ Make sure you enable the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.52.3", features = ["full"] } +tokio = { version = "1.52.4", features = ["full"] } ``` Then, on your main.rs: