From 84c4a6d89fe4988e630e18d592908d12bdd017cb Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Thu, 12 Aug 2021 15:37:26 +0200 Subject: [PATCH] task: quickly send task to heap on debug mode (#4009) --- tokio/src/task/spawn.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tokio/src/task/spawn.rs b/tokio/src/task/spawn.rs index 3c577b82d..065d38f54 100644 --- a/tokio/src/task/spawn.rs +++ b/tokio/src/task/spawn.rs @@ -127,7 +127,13 @@ cfg_rt! { T: Future + Send + 'static, T::Output: Send + 'static, { - spawn_inner(future, None) + // preventing stack overflows on debug mode, by quickly sending the + // task to the heap. + if cfg!(debug_assertions) && std::mem::size_of::() > 2048 { + spawn_inner(Box::pin(future), None) + } else { + spawn_inner(future, None) + } } #[cfg_attr(tokio_track_caller, track_caller)]