tokio::time::sleep blocks other requests #2436
-
SummaryI am trying to simulate requests taking some time to complete using Here's my code: use std::time::Duration;
use axum::Router;
use axum::routing::get;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(root));
let listener = tokio::net::TcpListener::bind("127.0.0.1:8082").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn root() -> &'static str {
tokio::time::sleep(Duration::from_secs(10)).await;
"Hello, World!"
} Run it, open 2 tabs in the browser. I expect both of them to load in ~10 seconds. Instead, it takes 10 seconds to load the first one and almost 20 seconds to load the second one (depending on how quickly you open second tab after the first one). Why does it behave like that? I tried searching and all I've seen is that it should occur when you (incorrectly) use axum version 0.7.2, tokio version 1.35.0 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Your browser won't create two independent connections to the same host, it serializes the requests. This is not the first time people have stumbled upon this and created an axum issue / discussion, but if you try with browser + curl, or two curl commands you should see that the server is behaving normally. |
Beta Was this translation helpful? Give feedback.
Your browser won't create two independent connections to the same host, it serializes the requests. This is not the first time people have stumbled upon this and created an axum issue / discussion, but if you try with browser + curl, or two curl commands you should see that the server is behaving normally.