Skip to content

Commit c35ffd2

Browse files
committed
fix: explicit runtime drop and join to prevent async context panic
1 parent a42be52 commit c35ffd2

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

bins/validator-node/src/wasm_executor.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -922,25 +922,28 @@ impl WasmChallengeExecutor {
922922
let key = platform_distributed_storage::StorageKey::new("wasm", module_path);
923923

924924
// Spawn a new thread with its own runtime to avoid nesting runtimes
925-
let (tx, rx) = std::sync::mpsc::channel();
926-
std::thread::spawn(move || {
927-
let rt = tokio::runtime::Builder::new_current_thread()
925+
// Use join() to ensure thread completes before returning
926+
let handle = std::thread::spawn(move || {
927+
let rt = match tokio::runtime::Builder::new_current_thread()
928928
.enable_all()
929-
.build();
930-
let result = match rt {
931-
Ok(rt) => rt.block_on(async {
932-
storage
933-
.get(&key, platform_distributed_storage::GetOptions::default())
934-
.await
935-
.ok()
936-
.flatten()
937-
}),
938-
Err(_) => None,
929+
.build()
930+
{
931+
Ok(rt) => rt,
932+
Err(_) => return None,
939933
};
940-
let _ = tx.send(result);
934+
let result = rt.block_on(async {
935+
storage
936+
.get(&key, platform_distributed_storage::GetOptions::default())
937+
.await
938+
.ok()
939+
.flatten()
940+
});
941+
// Explicitly shutdown runtime before thread exit
942+
drop(rt);
943+
result
941944
});
942945

943-
match rx.recv() {
946+
match handle.join() {
944947
Ok(Some(stored)) => {
945948
info!(
946949
module = module_path,

0 commit comments

Comments
 (0)