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 535abe3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/wasix/src/os/command/builtins/cmd_wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -96,8 +96,15 @@ 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 535abe3

Please sign in to comment.