From 535abe3c583ed1cdf7af667a2a79e67e678545b2 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Mon, 23 Oct 2023 14:17:31 +0200 Subject: [PATCH] fix: Fix async runtime mismatch in virtual "wasmer run" command The virtual "wasmer run" command available in wasix was switched to a inline waker for resolving the future, but it calls BinaryPackage::from_registry, which needs to run in a tokio runtime, due to doing web requests for package retrieval. Easily fixed by delegating to the main runtime. Closes #4269 --- lib/wasix/src/os/command/builtins/cmd_wasmer.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/wasix/src/os/command/builtins/cmd_wasmer.rs b/lib/wasix/src/os/command/builtins/cmd_wasmer.rs index 9f7afbba1d9..e7e87d1867f 100644 --- a/lib/wasix/src/os/command/builtins/cmd_wasmer.rs +++ b/lib/wasix/src/os/command/builtins/cmd_wasmer.rs @@ -2,7 +2,7 @@ use std::{any::Any, sync::Arc}; use crate::{ os::task::{OwnedTaskStatus, TaskJoinHandle}, - runtime::task_manager::InlineWaker, + runtime::task_manager::{InlineWaker}, SpawnError, }; use wasmer::{FunctionEnvMut, Store}; @@ -96,8 +96,15 @@ impl CmdWasmer { } pub async fn get_package(&self, name: &str) -> Result { + // Need to make sure this task runs on the main runtime. + let (tx, rx) = tokio::sync::oneshot::channel(); let specifier = name.parse()?; - BinaryPackage::from_registry(&specifier, &*self.runtime).await + let rt = self.runtime.clone(); + self.runtime.task_manager().task_shared(Box::new(|| Box::pin(async move { + let res = BinaryPackage::from_registry(&specifier, rt.as_ref()).await; + tx.send(res).expect("could not send response to output channel"); + })))?; + rx.await.map_err(|_| anyhow::anyhow!("package retrieval response channel died"))? } }