You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platform Darwin Ryans-Air 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:07 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8110 arm64
Description tokio::time::timeout does not always return an Error when the timeout is reached.
When calling long-running sync code in an async block, or async functions that do not yield, then timeout will not return an error, even if the timeout has been exceeded.
use std::time::Instant;use tokio::time::Duration;#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{println!("start");
tokio::time::timeout(Duration::from_secs(2),async{expensive_sync_fn();other_async_fn().await;}).await?;println!("done");Ok(())}fnexpensive_sync_fn(){let start = Instant::now();loop{ifInstant::now().duration_since(start).as_secs() > 3{break;}}}asyncfnother_async_fn(){println!("other async fn.");// Uncommenting this will cause the timeout to return a deadline exceeded error.// tokio::time::sleep(Duration::from_millis(10)).await;}
What I expected to happen is that timeout would return an error due to the timeout being exceeded, even if it could not interrupt the current execution, on completion of the block it should check and return the error.
If this is not possible, then the documentation should be amended to state this behaviour.
The text was updated successfully, but these errors were encountered:
Version
1.21.2
Platform
Darwin Ryans-Air 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:07 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8110 arm64
Description
tokio::time::timeout
does not always return anError
when the timeout is reached.When calling long-running sync code in an
async
block, orasync
functions that do not yield, thentimeout
will not return an error, even if the timeout has been exceeded.What I expected to happen is that
timeout
would return an error due to the timeout being exceeded, even if it could not interrupt the current execution, on completion of the block it should check and return the error.If this is not possible, then the documentation should be amended to state this behaviour.
The text was updated successfully, but these errors were encountered: