Skip to content

Commit 7ec21e9

Browse files
authored
Added task id on warn_on_block messages (#57)
* Added task_id to warn-on-block message * Updated version
1 parent f435918 commit 7ec21e9

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ members = [
1616
]
1717

1818
[workspace.dependencies]
19-
spawned-rt = { path = "rt", version = "0.4.0" }
20-
spawned-concurrency = { path = "concurrency", version = "0.4.0" }
19+
spawned-rt = { path = "rt", version = "0.4.1" }
20+
spawned-concurrency = { path = "concurrency", version = "0.4.1" }
2121
tracing = { version = "0.1.41", features = ["log"] }
2222
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
2323

2424
[workspace.package]
25-
version = "0.4.0"
25+
version = "0.4.1"
2626
license = "MIT"
2727
edition = "2021"

concurrency/src/tasks/gen_server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ mod warn_on_block {
328328
cx: &mut std::task::Context<'_>,
329329
) -> std::task::Poll<Self::Output> {
330330
let type_id = std::any::type_name::<F>();
331+
let task_id = rt::task_id();
331332
let this = self.project();
332333
let now = Instant::now();
333334
let res = this.inner.poll(cx);
334335
let elapsed = now.elapsed();
335336
if elapsed > Duration::from_millis(10) {
336-
warn!(future = ?type_id, elapsed = ?elapsed, "Blocking operation detected");
337+
warn!(task = ?task_id, future = ?type_id, elapsed = ?elapsed, "Blocking operation detected");
337338
}
338339
res
339340
}

examples/busy_genserver_warning/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl GenServer for BusyWorker {
4444
_: Self::CastMsg,
4545
handle: &GenServerHandle<Self>,
4646
) -> CastResponse {
47-
info!("sleeping");
47+
info!(taskid = ?rt::task_id(), "sleeping");
4848
thread::sleep(Duration::from_millis(542));
4949
handle.clone().cast(()).await.unwrap();
5050
// This sleep is needed to yield control to the runtime.

rt/src/tasks/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use crate::tasks::tokio::oneshot;
1818
pub use crate::tasks::tokio::sleep;
1919
pub use crate::tasks::tokio::timeout;
2020
pub use crate::tasks::tokio::CancellationToken;
21-
pub use crate::tasks::tokio::{spawn, spawn_blocking, JoinHandle, Runtime};
21+
pub use crate::tasks::tokio::{spawn, spawn_blocking, task_id, JoinHandle, Runtime};
2222
pub use crate::tasks::tokio::{BroadcastStream, ReceiverStream};
2323
use std::future::Future;
2424

rt/src/tasks/tokio/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod oneshot;
44

55
pub use tokio::{
66
runtime::Runtime,
7-
task::{spawn, spawn_blocking, JoinHandle},
7+
task::{id as task_id, spawn, spawn_blocking, JoinHandle},
88
time::{sleep, timeout},
99
};
1010
pub use tokio_stream::wrappers::{BroadcastStream, UnboundedReceiverStream as ReceiverStream};

0 commit comments

Comments
 (0)