Stream: git-wasmtime

Topic: wasmtime / issue #11348 `LowerContext` is not always used...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2025 at 16:44):

alexcrichton assigned dicej to issue #11348.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2025 at 16:44):

alexcrichton opened issue #11348:

Lowering into WebAssembly may require calling the realloc component model abi option to allocate space for a returned list, for example. WebAssembly in async mode must always be invoked on a fiber to support suspension at any time, for example with epochs or fuel injecting yields. Currently the component-model-async implementation does not always create and use a LowerContext on a fiber which will result in panics that fiber-related contextual information is unavailable.

This was discovered in review of https://github.com/bytecodealliance/wasmtime/pull/11325 and while that has an attempted solution for futures and streams it was also discovered that the solution isn't complete. I'm opening issue to keep track of this and take notes over time as necessary.

I shared with @dicej a small patch:

diff --git a/crates/wasmtime/src/runtime/component/func/options.rs b/crates/wasmtime/src/runtime/component/func/options.rs
index 620e5a71d5..a839772824 100644
--- a/crates/wasmtime/src/runtime/component/func/options.rs
+++ b/crates/wasmtime/src/runtime/component/func/options.rs
@@ -241,6 +241,11 @@ impl<'a, T: 'static> LowerContext<'a, T> {
         types: &'a ComponentTypes,
         instance: Instance,
     ) -> LowerContext<'a, T> {
+        if cfg!(debug_assertions) {
+            if store.engine().config().async_support {
+                store.0.with_blocking(|_, _| {});
+            }
+        }
         LowerContext {
             store,
             options,

which can be used to assert that LowerContext is created on a fiber. This currently panics many tests in the component-async-tests crate (and probably others). The current plan is to fix these panics then perhaps move this assertion to realloc instead to have a fast path where "flat" types can skip the fiber if they don't need realloc.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2025 at 16:44):

alexcrichton added the wasm-proposal:component-model-async label to Issue #11348.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2025 at 23:01):

dicej closed issue #11348:

Lowering into WebAssembly may require calling the realloc component model abi option to allocate space for a returned list, for example. WebAssembly in async mode must always be invoked on a fiber to support suspension at any time, for example with epochs or fuel injecting yields. Currently the component-model-async implementation does not always create and use a LowerContext on a fiber which will result in panics that fiber-related contextual information is unavailable.

This was discovered in review of https://github.com/bytecodealliance/wasmtime/pull/11325 and while that has an attempted solution for futures and streams it was also discovered that the solution isn't complete. I'm opening issue to keep track of this and take notes over time as necessary.

I shared with @dicej a small patch:

diff --git a/crates/wasmtime/src/runtime/component/func/options.rs b/crates/wasmtime/src/runtime/component/func/options.rs
index 620e5a71d5..a839772824 100644
--- a/crates/wasmtime/src/runtime/component/func/options.rs
+++ b/crates/wasmtime/src/runtime/component/func/options.rs
@@ -241,6 +241,11 @@ impl<'a, T: 'static> LowerContext<'a, T> {
         types: &'a ComponentTypes,
         instance: Instance,
     ) -> LowerContext<'a, T> {
+        if cfg!(debug_assertions) {
+            if store.engine().config().async_support {
+                store.0.with_blocking(|_, _| {});
+            }
+        }
         LowerContext {
             store,
             options,

which can be used to assert that LowerContext is created on a fiber. This currently panics many tests in the component-async-tests crate (and probably others). The current plan is to fix these panics then perhaps move this assertion to realloc instead to have a fast path where "flat" types can skip the fiber if they don't need realloc.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 30 2025 at 23:01):

dicej commented on issue #11348:

Fixed by #11353


Last updated: Dec 06 2025 at 06:05 UTC