The affected versions of Wasmtime can panic if the host embedder drops the future returned by wasmtime::component::[Typed]Func::call_async before it resolves.
Details
Starting with Wasmtime 39.0.0, the component-model-async feature became the default, which brought with it a new implementation of [Typed]Func::call_async which made it capable of calling async-typed guest export functions. However, that implementation had a bug leading to a panic under certain circumstances:
- The host embedding calls
[Typed]Func::call_async on a function exported by a component, polling the returned Future once.
- The component function yields control to the async runtime (e.g. Tokio), e.g. due to a call to host function registered using
LinkerInstance::func_wrap_async which yields, or due an epoch interruption.
- The host embedding drops the
Future after polling it once. This leaves the component instance in a non-reenterable state since the call never had a chance to complete.
- The host embedding calls
[Typed]Func::call_async again, polling the returned Future. Since the component instance cannot be entered at this point, the call traps, but not before allocating a task and thread for the call.
- The host embedding ignores the trap and drops the
Future. This panics due to the runtime attempting to dispose of the task created above, which panics since the thread has not yet exited.
Impact
When a host embedder using the affected versions of Wasmtime calls wasmtime::component::[Typed]Func::call_async on a guest export and then drops the returned future without waiting for it to resolve, and then does so again with the same component instance, Wasmtime will panic. Embeddings that have the component-model-async compile-time feature disabled are unaffected.
Patches
Wasmtime 40.0.4 and 41.0.4 have been patched to fix this issue. Versions 42.0.0 and later are not affected.
Workarounds
If an embedding is not actually using any component-model-async features then disabling the component-model-async Cargo feature can work around this issue. This issue can also be worked around by either ensuring every call_async future is awaited until it completes or refraining from using the Store again after dropping a not-yet-resolved call_async future.
Resources
This was first reported in https://bytecodealliance.zulipchat.com/#narrow/channel/206238-general/topic/Panic.20in.20Wasmtime.2041.2E0.2E3.20.28runtime.2Fconcurrent.2Fcomponent.29
References
The affected versions of Wasmtime can panic if the host embedder drops the future returned by
wasmtime::component::[Typed]Func::call_asyncbefore it resolves.Details
Starting with Wasmtime 39.0.0, the
component-model-asyncfeature became the default, which brought with it a new implementation of[Typed]Func::call_asyncwhich made it capable of calling async-typed guest export functions. However, that implementation had a bug leading to a panic under certain circumstances:[Typed]Func::call_asyncon a function exported by a component, polling the returnedFutureonce.LinkerInstance::func_wrap_asyncwhich yields, or due an epoch interruption.Futureafter polling it once. This leaves the component instance in a non-reenterable state since the call never had a chance to complete.[Typed]Func::call_asyncagain, polling the returnedFuture. Since the component instance cannot be entered at this point, the call traps, but not before allocating a task and thread for the call.Future. This panics due to the runtime attempting to dispose of the task created above, which panics since the thread has not yet exited.Impact
When a host embedder using the affected versions of Wasmtime calls
wasmtime::component::[Typed]Func::call_asyncon a guest export and then drops the returned future without waiting for it to resolve, and then does so again with the same component instance, Wasmtime will panic. Embeddings that have thecomponent-model-asynccompile-time feature disabled are unaffected.Patches
Wasmtime 40.0.4 and 41.0.4 have been patched to fix this issue. Versions 42.0.0 and later are not affected.
Workarounds
If an embedding is not actually using any component-model-async features then disabling the
component-model-asyncCargo feature can work around this issue. This issue can also be worked around by either ensuring everycall_asyncfuture is awaited until it completes or refraining from using theStoreagain after dropping a not-yet-resolvedcall_asyncfuture.Resources
This was first reported in https://bytecodealliance.zulipchat.com/#narrow/channel/206238-general/topic/Panic.20in.20Wasmtime.2041.2E0.2E3.20.28runtime.2Fconcurrent.2Fcomponent.29
References