-
-
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
Rocket hangs when spawning future on current runtime #1736
Comments
#[rocket::post("/spawn", format = "application/json", data = "<text>")]
async fn spawn_endpoint(text: String) -> Result<String, ()> {
tokio::task::spawn_blocking(|| run_on_current_thread(123)).await;
Ok(text.to_uppercase())
} This behavior is not particular to Rocket, either: removing the |
Thank you @jebrosen for solving my issue and clarifying that this is rather a async/tokio understanding issue. Using I have a follow-up (tokio) question based on your answer: Where and why does my spawned future "disapear", i.e. the code in |
I'm closing this as the core issue has been solved. Feel free to continue commenting. |
I think this has been more completely answered by Alice on the Tokio discord, but I'll leave this here for anyone else stumbling upon it:
I removed the
After calling So, without single thread runtime: And with single thread runtime:
Tuning the number of worker threads may happen to work in some examples, but it is not a reliable solution for this kind of problem. Suppose you had 8 worker threads, and 8 simultaneous users accessed the |
Description
I manually create a tokio runtime and launch my rocket. Then, when I spawn threads on that runtime, the future is not executed and rocket hangs (cannot even be killed via Ctrl+C, but SIGTERM works).
To Reproduce
Start a server using
cargo run
with non-working code example below and curl to trigger.Expected Behavior
I expected to see "the same behavior as when running tokio_main", i.e. the
async fn work()
code should be executed and print to the screen.Environment:
Additional Context
new_multi_thread
does not work eitherThe text was updated successfully, but these errors were encountered: