Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Don't queue instantiation work on failure (#15093)

Alex Crichton1b8d6acc425f
diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs
index 560389d31e..960853a81f 100644
--- a/crates/wasmtime/src/runtime/component/concurrent.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent.rs
@@ -1784,6 +1784,8 @@ impl<T> StoreContextMut<'_, T> {
instance: ModuleInstance,
callee: Option<RuntimeInstance>,
) -> Result<ModuleInstance> {
+ // See `Func::call_async` for why this is checked up front.
+ self.0.check_event_loop_not_running()?;
let (tx, rx) = oneshot::channel();
let token = StoreToken::new(self.as_context_mut());
self.0.queue_task(move |store| {
diff --git a/tests/all/component_model/async.rs b/tests/all/component_model/async.rs
index d5c7c75010..a091ee401d 100644
--- a/tests/all/component_model/async.rs
+++ b/tests/all/component_model/async.rs
@@ -3419,9 +3419,9 @@ async fn task_group_hook_fails_to_enter_call_async() -> Result<()> {
Ok(())
}
-/// `Func::call_async` and `TypedFunc::call_async` from within a host function,
-/// while the event loop is already running, fail without queueing the call to
-/// run later.
+/// `Func::call_async`, `TypedFunc::call_async` and `instantiate_async` from
+/// within a host function, while the event loop is already running, fail
+/// without queueing the call or start function to run later.
#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn call_async_from_host_function() -> Result<()> {
@@ -3442,6 +3442,15 @@ async fn call_async_from_host_function() -> Result<()> {
(func (export "trap") (canon lift (core func $i "trap")))
)"#,
)?;
+ let trap_on_start = Component::new(
+ &engine,
+ r#"(component
+ (core module $m
+ (func $start unreachable)
+ (start $start))
+ (core instance (instantiate $m))
+ )"#,
+ )?;
let trap = Arc::new(Mutex::new(None::<Func>));
let mut linker = Linker::new(&engine);
linker.root().func_wrap("host", {
@@ -3453,6 +3462,10 @@ async fn call_async_from_host_function() -> Result<()> {
let trap = trap.typed::<(), ()>(&store)?;
let result = trap.call_async(&mut store, ()).now_or_never();
assert!(matches!(result, Some(Err(_))));
+ let result = Linker::new(store.engine())
+ .instantiate_async(&mut store, &trap_on_start)
+ .now_or_never();
+ assert!(matches!(result, Some(Err(_))));
Ok(())
}
})?;