From 50aeef76ec8e0e6118a85322ac34713dd4cf85f3 Mon Sep 17 00:00:00 2001 From: Esteban Dimitroff Hodi Date: Thu, 2 Oct 2025 09:13:49 -0300 Subject: [PATCH 1/2] Added task_id to warn-on-block message --- concurrency/src/tasks/gen_server.rs | 3 ++- examples/busy_genserver_warning/main.rs | 2 +- rt/src/tasks/mod.rs | 2 +- rt/src/tasks/tokio/mod.rs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/concurrency/src/tasks/gen_server.rs b/concurrency/src/tasks/gen_server.rs index 7b2fb15..064d42a 100644 --- a/concurrency/src/tasks/gen_server.rs +++ b/concurrency/src/tasks/gen_server.rs @@ -328,12 +328,13 @@ mod warn_on_block { cx: &mut std::task::Context<'_>, ) -> std::task::Poll { let type_id = std::any::type_name::(); + let task_id = rt::task_id(); let this = self.project(); let now = Instant::now(); let res = this.inner.poll(cx); let elapsed = now.elapsed(); if elapsed > Duration::from_millis(10) { - warn!(future = ?type_id, elapsed = ?elapsed, "Blocking operation detected"); + warn!(task = ?task_id, future = ?type_id, elapsed = ?elapsed, "Blocking operation detected"); } res } diff --git a/examples/busy_genserver_warning/main.rs b/examples/busy_genserver_warning/main.rs index e799996..2d6d6ef 100644 --- a/examples/busy_genserver_warning/main.rs +++ b/examples/busy_genserver_warning/main.rs @@ -44,7 +44,7 @@ impl GenServer for BusyWorker { _: Self::CastMsg, handle: &GenServerHandle, ) -> CastResponse { - info!("sleeping"); + info!(taskid = ?rt::task_id(), "sleeping"); thread::sleep(Duration::from_millis(542)); handle.clone().cast(()).await.unwrap(); // This sleep is needed to yield control to the runtime. diff --git a/rt/src/tasks/mod.rs b/rt/src/tasks/mod.rs index 5291f69..09d3294 100644 --- a/rt/src/tasks/mod.rs +++ b/rt/src/tasks/mod.rs @@ -18,7 +18,7 @@ pub use crate::tasks::tokio::oneshot; pub use crate::tasks::tokio::sleep; pub use crate::tasks::tokio::timeout; pub use crate::tasks::tokio::CancellationToken; -pub use crate::tasks::tokio::{spawn, spawn_blocking, JoinHandle, Runtime}; +pub use crate::tasks::tokio::{spawn, spawn_blocking, task_id, JoinHandle, Runtime}; pub use crate::tasks::tokio::{BroadcastStream, ReceiverStream}; use std::future::Future; diff --git a/rt/src/tasks/tokio/mod.rs b/rt/src/tasks/tokio/mod.rs index eac39e0..1bd2bf5 100644 --- a/rt/src/tasks/tokio/mod.rs +++ b/rt/src/tasks/tokio/mod.rs @@ -4,7 +4,7 @@ pub mod oneshot; pub use tokio::{ runtime::Runtime, - task::{spawn, spawn_blocking, JoinHandle}, + task::{id as task_id, spawn, spawn_blocking, JoinHandle}, time::{sleep, timeout}, }; pub use tokio_stream::wrappers::{BroadcastStream, UnboundedReceiverStream as ReceiverStream}; From 9c2c446a671367b3da26af303831db5cb9c56fa2 Mon Sep 17 00:00:00 2001 From: Esteban Dimitroff Hodi Date: Thu, 2 Oct 2025 18:19:03 -0300 Subject: [PATCH 2/2] Updated version --- Cargo.lock | 4 ++-- Cargo.toml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13b3249..b9eb9ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,7 +1197,7 @@ dependencies = [ [[package]] name = "spawned-concurrency" -version = "0.4.0" +version = "0.4.1" dependencies = [ "futures", "pin-project-lite", @@ -1210,7 +1210,7 @@ dependencies = [ [[package]] name = "spawned-rt" -version = "0.4.0" +version = "0.4.1" dependencies = [ "crossbeam", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 802efaf..2b55e5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,12 @@ members = [ ] [workspace.dependencies] -spawned-rt = { path = "rt", version = "0.4.0" } -spawned-concurrency = { path = "concurrency", version = "0.4.0" } +spawned-rt = { path = "rt", version = "0.4.1" } +spawned-concurrency = { path = "concurrency", version = "0.4.1" } tracing = { version = "0.1.41", features = ["log"] } tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } [workspace.package] -version = "0.4.0" +version = "0.4.1" license = "MIT" edition = "2021"