task: quickly send task to heap on debug mode (#4009)

This commit is contained in:
Blas Rodriguez Irizar
2021-08-12 15:37:26 +02:00
committed by GitHub
parent b501f25202
commit 84c4a6d89f
+7 -1
View File
@@ -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::<T>() > 2048 {
spawn_inner(Box::pin(future), None)
} else {
spawn_inner(future, None)
}
}
#[cfg_attr(tokio_track_caller, track_caller)]