From 08611067d7c47c69a9955cd58bf8fc7a796e4112 Mon Sep 17 00:00:00 2001 From: radik878 Date: Thu, 28 Aug 2025 11:24:18 +0300 Subject: [PATCH 1/2] chore(database): avoid panic by conditionally using block_in_place --- crates/database/interface/src/async_db.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/database/interface/src/async_db.rs b/crates/database/interface/src/async_db.rs index c30831e8ca..5889769ad3 100644 --- a/crates/database/interface/src/async_db.rs +++ b/crates/database/interface/src/async_db.rs @@ -190,7 +190,23 @@ impl HandleOrRuntime { F::Output: Send, { match self { - Self::Handle(handle) => tokio::task::block_in_place(move || handle.block_on(f)), + Self::Handle(handle) => { + // Use block_in_place only when we're currently inside a multi-threaded Tokio runtime. + // Otherwise, call handle.block_on directly to avoid panicking outside of a runtime. + let can_block_in_place = match Handle::try_current() { + Ok(current) => match current.runtime_flavor() { + tokio::runtime::RuntimeFlavor::CurrentThread => false, + _ => true, + }, + Err(_) => false, + }; + + if can_block_in_place { + tokio::task::block_in_place(move || handle.block_on(f)) + } else { + handle.block_on(f) + } + } Self::Runtime(rt) => rt.block_on(f), } } From 21e3512a2ab57ec1d1eb203a6e83df4ff5113296 Mon Sep 17 00:00:00 2001 From: radik878 Date: Thu, 11 Sep 2025 12:41:41 +0300 Subject: [PATCH 2/2] fix clippy --- crates/database/interface/src/async_db.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/database/interface/src/async_db.rs b/crates/database/interface/src/async_db.rs index 5889769ad3..5e42d0c9c1 100644 --- a/crates/database/interface/src/async_db.rs +++ b/crates/database/interface/src/async_db.rs @@ -194,10 +194,10 @@ impl HandleOrRuntime { // Use block_in_place only when we're currently inside a multi-threaded Tokio runtime. // Otherwise, call handle.block_on directly to avoid panicking outside of a runtime. let can_block_in_place = match Handle::try_current() { - Ok(current) => match current.runtime_flavor() { - tokio::runtime::RuntimeFlavor::CurrentThread => false, - _ => true, - }, + Ok(current) => !matches!( + current.runtime_flavor(), + tokio::runtime::RuntimeFlavor::CurrentThread + ), Err(_) => false, };