From 4689b2f145332e48d78f1ee5c5f955855a075ba2 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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/wasix/src/os/command/builtins/cmd_wasmer.rs b/lib/wasix/src/os/command/builtins/cmd_wasmer.rs index 9f7afbba1d9..90dbf644022 100644 --- a/lib/wasix/src/os/command/builtins/cmd_wasmer.rs +++ b/lib/wasix/src/os/command/builtins/cmd_wasmer.rs @@ -96,8 +96,19 @@ 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"))? } }