From 436d64c449a80f1c36b024daffd7f62b543961be Mon Sep 17 00:00:00 2001 From: Maxime Guerreiro Date: Mon, 11 May 2026 01:00:18 +0200 Subject: [PATCH] chore(rt): preserve executor caller locations Tokio task hooks report the source location of the tokio::spawn call. When runtime executor glue performs that spawn, the recorded location can point at the executor implementation itself. That is technically correct, but it hides the more useful callsite: the code path that asked the executor to create background work. Mark Executor::execute and the HTTP/2 executor forwarding traits with track_caller so task instrumentation can attribute spawned tasks to the caller that requested execution rather than to generic executor forwarding glue. --- src/rt/bounds.rs | 6 ++++++ src/rt/mod.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/rt/bounds.rs b/src/rt/bounds.rs index 0af623b1bf..710c93a5d0 100644 --- a/src/rt/bounds.rs +++ b/src/rt/bounds.rs @@ -18,6 +18,7 @@ mod h2_common { pub trait Http2UpgradedExec { #[doc(hidden)] + #[track_caller] fn execute_upgrade(&self, fut: UpgradedSendStreamTask); } @@ -26,6 +27,7 @@ mod h2_common { where E: Executor>, { + #[track_caller] fn execute_upgrade(&self, fut: UpgradedSendStreamTask) { self.execute(fut) } @@ -56,6 +58,7 @@ mod h2_client { T: Read + Write + Unpin, { #[doc(hidden)] + #[track_caller] fn execute_h2_future(&mut self, future: H2ClientFuture); } @@ -69,6 +72,7 @@ mod h2_client { H2ClientFuture: Future, T: Read + Write + Unpin, { + #[track_caller] fn execute_h2_future(&mut self, future: H2ClientFuture) { self.execute(future) } @@ -110,6 +114,7 @@ mod h2_server { super::Http2UpgradedExec + sealed::Sealed<(F, B)> + Clone { #[doc(hidden)] + #[track_caller] fn execute_h2stream(&mut self, fut: H2Stream); } @@ -122,6 +127,7 @@ mod h2_server { H2Stream: Future, B: Body, { + #[track_caller] fn execute_h2stream(&mut self, fut: H2Stream) { self.execute(fut) } diff --git a/src/rt/mod.rs b/src/rt/mod.rs index 0eb266974f..7371a30fde 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -44,5 +44,6 @@ pub use self::timer::{Sleep, Timer}; /// ``` pub trait Executor { /// Place the future into the executor to be run. + #[track_caller] fn execute(&self, fut: Fut); }