From 01f0ef5d28225c59a919f5f08b6cf46a32775f75 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 8 Sep 2026 13:04:55 -0700 Subject: [PATCH] Adjust the recursive `run_concurrent` check This commit adjust the previous `check_recursive_run` function found in `concurrent.rs` to instead be a check of the now-present `event_loop_running` bool. 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 with `instantiate_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 the `start` function. Spin executes the components in different stores, however, which is how this commit fixes that case. --- .../src/runtime/component/concurrent.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs index ce8e46eb6488..b7f8593a1f93 100644 --- a/crates/wasmtime/src/runtime/component/concurrent.rs +++ b/crates/wasmtime/src/runtime/component/concurrent.rs @@ -1224,7 +1224,13 @@ impl StoreContextMut<'_, T> { trap_on_idle: bool, ) -> Result { debug_assert!(self.0.concurrency_support()); - check_recursive_run(); + let already_running = self + .0 + .concurrent_state_mut_already_forced_current_thread() + .event_loop_running; + if already_running { + bail!("Recursive `StoreContextMut::run_concurrent` calls not supported") + } let token = StoreToken::new(self.as_context_mut()); struct Dropper<'a, T: 'static, V> { @@ -6103,16 +6109,6 @@ fn check_ambient_store(id: StoreId) { }); } -/// Assert that `StoreContextMut::run_concurrent` has not been called from -/// within an store's event loop. -fn check_recursive_run() { - tls::try_get(|store| { - if !matches!(store, tls::TryGet::None) { - panic!("Recursive `StoreContextMut::run_concurrent` calls not supported") - } - }); -} - fn unpack_callback_code(code: u32) -> (u32, u32) { (code & 0xF, code >> 4) }