Tokio timeout stuck on a loop. #4821
-
This is a simplified version of my code,
The output of this program is
It will keep going until I kill the process. Do I fundamentally misunderstand tokio and async? Isn't the timeout meant to stop the infinite loop? I read here that calling await gives the runtime a chance to swap tasks (hence the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This one panics as expected. How come the other one doesn't?
|
Beta Was this translation helpful? Give feedback.
-
So, the future created by the Rewrite empty wait as such: async fn empty_await() -> i32 {
tokio::task::yield_now().await;
0
} Many tokio async functions and futures use an internal budgeting system to force futures which would otherwise be ready to occasionally yield in order to mitigate this issue. |
Beta Was this translation helpful? Give feedback.
So, the future created by the
async move
block never actually yields because the inner future you await is always ready.Rewrite empty wait as such:
Many tokio async functions and futures use an internal budgeting system to force futures which would otherwise be ready to occasionally yield in order to mitigate this issue.