Skip to content

Commit

Permalink
fix: Fix async runtime mismatch in virtual "wasmer run" command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
theduke committed Oct 23, 2023
1 parent 9127dde commit 4689b2f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/wasix/src/os/command/builtins/cmd_wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,19 @@ impl CmdWasmer {
}

pub async fn get_package(&self, name: &str) -> Result<BinaryPackage, anyhow::Error> {
// 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"))?
}
}

Expand Down

0 comments on commit 4689b2f

Please sign in to comment.