-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
E-easyEffort: Easy! Start here :DEffort: Easy! Start here :DE-pr-welcomeThe feature is welcome to be added, instruction should be found in the issue.The feature is welcome to be added, instruction should be found in the issue.
Description
This bug was extremely hard to track down. I was wondering why my tokio runtime was failing even when spawned on separate thread. Note that I do know that running blocking tasks on tokio isn't a good idea. But I was trying to slowly migrate from blocking to non-blocking and this was interim state.
What would be great is
- the documentation should explicitly state that instantiating
client::blocking
inside tokio ends up with fireworks reqwest::blocking::Client
should actually use tokio'senter(false)
to check for runtime-inside-runtime and at least should fatal early on (e.g. something like "You should not run reqwest::blocking inside existing tokio runtime")
The smallest repro is
use reqwest;
use tokio;
#[tokio::main(flavor = "current_thread")]
async fn worker() {
println!("worker started!");
let client = reqwest::blocking::Client::new();
println!("worker ended");
}
pub fn main() {
worker();
}
Running this fails with
worker started!
thread 'main' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.', /home/ppershing/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.4.0/src/runtime/blocking/shutdown.rs:51:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
which isn't helpful at all if it happens inside larger codebase
ward, digizeph, eminence, tbarusseau, Herohtar and 29 more
Metadata
Metadata
Assignees
Labels
E-easyEffort: Easy! Start here :DEffort: Easy! Start here :DE-pr-welcomeThe feature is welcome to be added, instruction should be found in the issue.The feature is welcome to be added, instruction should be found in the issue.