fix: tokio, call future in context of runtime (#9310)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-09-10 17:39:22 +08:00 committed by GitHub
parent 13effe7f14
commit 51055a7e5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -172,7 +172,13 @@ impl Handler {
bail!("{}", err); bail!("{}", err);
} else { } else {
if contents.iter().any(|c| c.next_raw) { if contents.iter().any(|c| c.next_raw) {
match rt.block_on(timeout(1000, stream.next_raw())) { // Wrap the future with a `Timeout` in an async block to avoid panic.
// We cannot use `rt.block_on(timeout(1000, stream.next_raw()))` here, because it causes panic:
// thread '<unnamed>' panicked at D:\Projects\rust\rustdesk\libs\hbb_common\src\lib.rs:98:5:
// there is no reactor running, must be called from the context of a Tokio 1.x runtime
// note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
match rt.block_on(async { timeout(1000, stream.next_raw()).await })
{
Ok(Ok(mut data)) => { Ok(Ok(mut data)) => {
for c in &mut contents { for c in &mut contents {
if c.next_raw { if c.next_raw {