-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request is handled always by the same worker thread #2332
Comments
This is your browser serializing requests, not Rocket. Try using two different browsers to issue the two requests. |
It's possible that these are using the same engine underneath in some way, or that there's something else going on on Windows. Are you sure you have more than one available worker? I can't reproduce this on Linux using Chrome and Firefox, nor on MacOS. If you have no issue using two I would try 1) two browsers based on different engines, say Chrome and Firefox, or Edge and Firefox, 2) try a different server and see if it reacts in the same manner. |
@brunneng In your GIF, you make a request to |
That's fine. This isn't a problem since the thread is free. We would only expect another thread to be used with certainty if parallelism is required. That is, if the thread were busy. Given what we're seeing, I'm leaning towards saying that this is an issue with #[macro_use] extern crate rocket;
use std::time::Duration;
#[get("/")]
fn index() -> &'static str {
println!("Before sleep in thread: {}", thread_id::get());
std::thread::sleep(Duration::from_secs(5));
println!("After sleep in thread: {}", thread_id::get());
"Hello, from aaa!"
}
#[launch]
fn rocket() -> _ {
let rt_handle = rocket::tokio::runtime::Handle::current();
std::thread::spawn(move || {
loop {
std::thread::sleep(Duration::from_secs(1));
rt_handle.spawn(std::future::ready(()));
}
});
rocket::build().mount("/", routes![index])
} If this works, comment out lines 15 through 21 and confirm that the code still exhibits the erroneous behavior. If it does, we've found
Good. This means there's definitely no serialization going on from the browser side. |
Thanks for running that. Unfortunately this confirms that this is an issue with |
Description
In rocker 0.5.0-rc.2 all calls to endpoint are handled by the same worker thread. I have 16 worker threads by default.
If I put thread sleep 5 seconds in the request handler then the second concurrent call is not handled until the first call is finished.
I expected that different workers should handle calls.
To Reproduce
Here is my test program:
Cargo.toml:
On startup it prints:
Note: workers: 16.
Now we can call endpoint aaa. For this quickly refresh two open tabs in browser with line: http://127.0.0.1:8000/aaa
In logs we can see:
As you can see thread id is the same. The second request takes ~ 10 seconds to execute because of sequential execution but should be 5.
The same situation if we try to use async endpoint /bbb.
Expected Behavior
Requests should execute independently by random workers.
Environment:
Additional Context
If I run requests using curl from 2 cmd windows everything seems fine - different threads are picked for each request. But I don't understand why.
I also can reproduce the issue with postman.
The text was updated successfully, but these errors were encountered: