alexcrichton requested dicej for a review on PR #14302.
alexcrichton opened PR #14302 from alexcrichton:fix-spin to bytecodealliance:main:
This commit adjust the previous
check_recursive_runfunction found inconcurrent.rsto instead be a check of the now-presentevent_loop_runningbool. This allows disparate stores to run recursively as there should be no issue with that but still requires a single store just once and never recursively.This was discovered in Spin's update to Wasmtime 49 at spinframework/spin#3710 where delegation of an HTTP request from a p3 component (executed with
run_concurrent) to a p2 component (instantiated withinstantiate_async) started panicking with this recursive check in Wasmtime 49. The cause of this was the refactoring in #14146 where all instantiation now simulates the concurrent event loop where enabled for thestartfunction. Spin executes the components in different stores, however, which is how this commit fixes that case.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested wasmtime-core-reviewers for a review on PR #14302.
alexcrichton commented on PR #14302:
FWIW this program:
use std::any::Any; use wasmtime::component::{Component, InstancePre, Linker}; use wasmtime::{AsContext, Engine, Result, Store}; type Data = Option<Box<dyn Any + Send + Sync>>; #[tokio::main] async fn main() -> Result<()> { let engine = Engine::default(); let component = Component::new( &engine, r#" (component (import "a" (func $a async)) (core module $a (import "" "a" (func $a)) (func (export "run") (call $a)) (func (export "run2")) (func $f) (start $f) ) (core func $a (canon lower (func $a))) (core instance $i (instantiate $a (with "" (instance (export "a" (func $a)) )) )) (func (export "run") async (canon lift (core func $i "run"))) (func (export "run2") (canon lift (core func $i "run2"))) ) "#, )?; let mut store = Store::<Data>::new(&engine, None); let mut linker = Linker::<Data>::new(&engine); linker.root().func_wrap_concurrent("a", |caller, ()| { Box::pin(async move { let (mut store, pre): (_, InstancePre<Data>) = caller.with(|caller| { let store = Store::<Data>::new(caller.as_context().engine(), None); let pre: InstancePre<Data> = caller .as_context() .data() .as_ref() .unwrap() .downcast_ref::<InstancePre<Data>>() .unwrap() .clone(); (store, pre) }); let fut: std::pin::Pin<Box<dyn Future<Output = Result<_>> + Send + '_>> = Box::pin(pre.instantiate_async(&mut store)); fut.await?; Ok(()) }) })?; let instance = linker.instantiate_async(&mut store, &component).await?; let run = instance.get_typed_func::<(), ()>(&mut store, "run")?; *store.data_mut() = Some(Box::new(linker.instantiate_pre(&component)?)); store .run_concurrent(async |store| run.call_concurrent(store, ()).await) .await??; Ok(()) }runs on 48.0.1 but fails on 49.0.0-rc.1 which is what I was testing with and is a rough reduction of what Spin is doing.
:thumbs_up: dicej submitted PR review:
Thanks for investigating and fixing this!
alexcrichton added PR #14302 Adjust the recursive run_concurrent check to the merge queue.
github-merge-queue[bot] removed PR #14302 Adjust the recursive run_concurrent check from the merge queue.
github-actions[bot] added the label wasmtime:api on PR #14302.
alexcrichton added PR #14302 Adjust the recursive run_concurrent check to the merge queue.
:check: alexcrichton merged PR #14302.
alexcrichton removed PR #14302 Adjust the recursive run_concurrent check from the merge queue.
Last updated: Sep 20 2026 at 18:08 UTC