-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Calling wasi:cli/run#run function twice in the same component instance returns "unreachable
instruction executed" error
#10219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The wasp1->wasip2 adapter directly calls the wasmtime/crates/wasi-preview1-component-adapter/src/lib.rs Lines 117 to 126 in 73d6d6b
Wasip1 documents that
Wasi-libc has an explicit check for this which uses |
Thanks for the fast response! Ok makes sense, I'm not clear though on whether going forward that is also the case for wasip2 components that aren't adapting inner wasip1 modules? |
AFAIK there aren't clear semantics defined for WASIp2 at this time. The |
Ah ok got it, I updated my example repo to add a library package that implements the If I am understanding this correctly that is because the inner wasip1 module is now a "reactor" module not a "command" module, so the component adapter isn't calling Also I tried creating a component using the |
Long story short: this behavior is down to the toolchain that created the component, not wasmtime, and the toolchain may not change the way this works even if internals were updated to purely use p2 and not p1. This is an area that is not fully fleshed out yet. In wasip1 terms, the inner wasip1 module is still a "command" - its internal structure assumes, and enforces by trapping in this manner, that it is instantiated and then the exported function is run at most once. Internally, there is a module exporting The wasip2 spec doesn't describe that this export may be called at most once. We never carried over the command/reactor distinction into the wit era. De-facto, almost all cli run exports are implemented such that they will trap on a second call to that export on an instance. Any guest using wasi-libc - used by wasi-libc for C/C++, rustc for Rust, I believe Tinygo, and perhaps by others as well - ends up with that same check that bjorn3 linked to. As far as the distinction for "native" wasip2 vs p1 is concerned, the runtime doesn't care what the internal modules of a component are as long as the imports and exports conform to the wasip2 interfaces. It hasn't been anyone's priority to finish up the work in wasi-libc, wasi-sdk and rustc to get rid of the wasip1 use and the use of the p1->p2 adapter to create components. It would be nice for that to happen at some point - it would make binaries smaller, and likely allow for omitting unused import functions and other optimizations - but it hasn't been blocking progress elsewhere and everyone is quite busy, so its been on the backburner for a while. As far as the toolchains changing its behavior for the cli command world run functions: I don't know what all of the considerations are there off the top of my head, but I expect one of the biggest is that there is no precedent in POSIX for the |
Thanks for explaining the relationship between wasip1 modules and wasip2 components, I was a bit confused about how the command/reactor concept fit into the component model since I couldn't find much about it in wasip2 or component model documentation. I don't have any issue with not being able to call the That issue you linked is very helpful, I am trying to understand component instance reusability and the kinds of assumptions a host can make about reusing an instance, hence why I created this issue. Something like the reuse hint that was mentioned sounds like a good way for a host to generically know whether a component could have its instance reused or not. Thanks for all the information! |
Test Case
Clone example repo here: https://github.com/justingaffney/wasmtime-run-twice-error
Steps to Reproduce
cd guest
cargo component build --release
cd ../host
cargo run
Expected Results
Actual Results
Versions and Environment
Wasmtime version or commit: 29.0.1
Operating system: Windows 11
Architecture: x86_64
Extra Info
Not sure if calling the
wasi:cli/[email protected]#run
function multiple times on the same component instance is supposed to work or not, but it is not clear from the error whether this behaviour is expected or notThe text was updated successfully, but these errors were encountered: