pub fn block_on<F: core::future::Future>(mut runtime: Option<Runtime>, f: F) -> F::Output {
if runtime.is_none() {
runtime = Handle::try_current()
.is_err()
.then(|| Runtime::new().unwrap());
}
match runtime {
Some(runtime) => runtime.block_on(f),
None => futures::executor::block_on(f), // <= DeadLock here where it get called from tokio-runtimte-worker
}
}
let me try to explain the problem, im using tokio as my async lib, and rayon to do some CPU task par_iter().filter_map
when block_on called from cli.exe!std::sys.... threads (which is should always do be cause its Rayon threads) it works normally. but when called from tokio-runtime-worker is case a deadlock, the real problem is why it even get called from tokio-runtime-worker its same code and same execution path, but some times it get called from tokio-runtime-worker.
Here is the execution path:
Async tokio task tokio::spawn -> async task -> async task that contains rayon call par_iter().filter_map -> inside filter_map calls a function that call block_on
i know i can't explain the problem in a good way so if u have a question pls ask.
There a two images that show the stacktrace