From 82597cf75cc22d7a369154e057bcb8d9ddc7f8b8 Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Fri, 30 Jul 2021 22:29:20 +0200 Subject: [PATCH 1/2] task: quickly send task to heap on debug mode Ref: #2055 --- 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 3c577b82d86..76f39d7070f 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) { + spawn_inner(Box::pin(future), None) + } else { + spawn_inner(future, None) + } } #[cfg_attr(tokio_track_caller, track_caller)] From 57863ca9a9c9f2a57ce0a46df3e4d22f475f3c1f Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Thu, 12 Aug 2021 11:54:05 +0200 Subject: [PATCH 2/2] Update tokio/src/task/spawn.rs Co-authored-by: Alice Ryhl --- tokio/src/task/spawn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/task/spawn.rs b/tokio/src/task/spawn.rs index 76f39d7070f..065d38f54b5 100644 --- a/tokio/src/task/spawn.rs +++ b/tokio/src/task/spawn.rs @@ -129,7 +129,7 @@ cfg_rt! { { // preventing stack overflows on debug mode, by quickly sending the // task to the heap. - if cfg!(debug_assertions) { + if cfg!(debug_assertions) && std::mem::size_of::() > 2048 { spawn_inner(Box::pin(future), None) } else { spawn_inner(future, None)