Why blocking in same routers? #2321
Answered
by
jplatte
VladimirShestakov
asked this question in
Q&A
-
Why does a request to route /api/1 block second request to the /api/1 route? At the same time, does not block request to route /api/2. That is, requests for the same routes queue up. How to fix bloking in same routes? #[tokio::main]
async fn main() {
let app = Router::new()
.route("/api/1", get(handler))
.route("/api/2", get(handler));
axum::Server::bind(&"127.0.0.1:5000".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
}
async fn handler() -> impl IntoResponse {
const MESSAGE: &str = "Build Simple CRUD API in Rust using Axum";
let json_response = serde_json::json!({
"status": "success",
"message": MESSAGE
});
// emulate a long wait
tokio::time::sleep(Duration::from_millis(5000)).await;
Json(json_response)
} axum = "0.6.20" |
Beta Was this translation helpful? Give feedback.
Answered by
jplatte
Nov 15, 2023
Replies: 1 comment 1 reply
-
How are you testing this? It's likely a client-side synchronization, not the server being unable to handle both requests in parallel. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
VladimirShestakov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How are you testing this? It's likely a client-side synchronization, not the server being unable to handle both requests in parallel.