xiaocq2001 opened issue #11086:
Steps to Reproduce
- first, modify
examples/component/wasm/guest.rsto generate panic in some cases, let's say generate panic when input is over 100.0- second, modify
examples/component/main.rsto invoke the guest function several times and print the result directly, e.g., use these values: 0.0, 32.0, 100.0, 100.1, 31.0, 50.0.- Check output to see function call fails
Expected Results
Just value >100 panics and since panic is catched by trap, I expect the subsequent component calls recover to normal state.
Actual Results
Component calls after the panic keep failing, returning "wasm trap: cannot enter component instance"
Versions and Environment
Wasmtime version or commit: cfe17cb1c61658a157e7ad9da2ecbe5f314a2536
Operating system: Ubuntu
Architecture: wasm32-unknown-unknown, wasm32-wasip2 and maybe more
Extra Info
My testing output:
Converted 0 to: Ok(32.0) Converted 32 to: Ok(89.6) Converted 100 to: Ok(212.0) Converted 100.1 to: Err(error while executing at wasm backtrace: 0: 0x2e65 - guest.wasm!__rustc[90fd524071601a38]::__rust_abort 1: 0x3980 - guest.wasm!__rustc[90fd524071601a38]::__rust_start_panic 2: 0x393e - guest.wasm!__rustc[90fd524071601a38]::rust_panic 3: 0x391f - guest.wasm!std::panicking::rust_panic_with_hook::h885a2e0f7cb6094c 4: 0x2f31 - guest.wasm!std::panicking::begin_panic_handler::{{closure}}::hf631a5b49e1d8742 5: 0x2e6b - guest.wasm!std::sys::backtrace::__rust_end_short_backtrace::h055708a75b60b26d 6: 0x349a - guest.wasm!__rustc[90fd524071601a38]::rust_begin_unwind 7: 0x3d6f - guest.wasm!core::panicking::panic_fmt::h3b9ae52b0e452a99 8: 0x3e9 - guest.wasm!<guest::GuestComponent as guest::Guest>::convert_celsius_to_fahrenheit::hf763edc0af92d5f6 9: 0x2f7 - guest.wasm!guest::_export_convert_celsius_to_fahrenheit_cabi::h7eba130e8e72a055 10: 0x427 - guest.wasm!convert-celsius-to-fahrenheit note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information Caused by: wasm trap: wasm `unreachable` instruction executed Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: wasmtime::runtime::trap::from_runtime_box at ./crates/wasmtime/src/runtime/trap.rs:101:39 3: wasmtime::runtime::func::invoke_wasm_and_catch_traps::{{closure}} at ./crates/wasmtime/src/runtime/func.rs:1535:28 4: core::result::Result<T,E>::map_err at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:914:27 5: wasmtime::runtime::func::invoke_wasm_and_catch_traps at ./crates/wasmtime/src/runtime/func.rs:1535:16 6: wasmtime::runtime::func::Func::call_unchecked_raw at ./crates/wasmtime/src/runtime/func.rs:1021:9 7: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func.rs:456:13 8: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl at ./crates/wasmtime/src/runtime/component/func/typed.rs:234:27 9: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call at ./crates/wasmtime/src/runtime/component/func/typed.rs:164:14 10: component::_::<impl component::Convert>::call_convert_celsius_to_fahrenheit at ./examples/component/main.rs:10:1 11: component::main at ./examples/component/main.rs:59:30 12: core::ops::function::FnOnce::call_once at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 13: std::sys::backtrace::__rust_begin_short_backtrace at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18 14: std::rt::lang_start::{{closure}} at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18 15: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/core/src/ops/function.rs:284:21 16: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 17: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 18: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 19: std::rt::lang_start_internal::{{closure}} at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:175:24 20: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 21: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 22: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 23: std::rt::lang_start_internal at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:171:5 24: std::rt::lang_start at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5 25: main 26: <unknown> 27: __libc_start_main 28: _start) Converted 31 to: Err(wasm trap: cannot enter component instance Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: anyhow::kind::Trait::new at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/kind.rs:95:15 3: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func.rs:432:17 4: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl at ./crates/wasmtime/src/runtime/component/func/typed.rs:234:27 5: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call at ./crates/wasmtime/src/runtime/component/func/typed.rs:164:14 6: component::_::<impl component::Convert>::call_convert_celsius_to_fahrenheit at ./examples/component/main.rs:10:1 7: component::main at ./examples/component/main.rs:59:30 8: core::ops::function::FnOnce::call_once at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 9: std::sys::backtrace::__rust_begin_short_backtrace at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18 10: std::rt::lang_start::{{closure}} at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18 11: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/core/src/ops/function.rs:284:21 12: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 13: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 14: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 15: std::rt::lang_start_internal::{{closure}} at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:175:24 16: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 17: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 18: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 19: std::rt::lang_start_internal at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:171:5 20: std::rt::lang_start at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5 21: main 22: <unknown> 23: __libc_start_main 24: _start) Converted 50 to: Err(wasm trap: cannot enter component instance Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: anyhow::kind::Trait::new at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/kind.rs:95:15 3: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func.r [message truncated]
xiaocq2001 added the bug label to Issue #11086.
bjorn3 commented on issue #11086:
This is intentional. Once a component traps, you are no longer allowed to enter it. LLVM considers continuing after a trap UB. While core wasm doesn't enfore that you don't re-enter the module after a trap, the wasm component model does enforce this.
alexcrichton closed issue #11086:
Steps to Reproduce
- first, modify
examples/component/wasm/guest.rsto generate panic in some cases, let's say generate panic when input is over 100.0- second, modify
examples/component/main.rsto invoke the guest function several times and print the result directly, e.g., use these values: 0.0, 32.0, 100.0, 100.1, 31.0, 50.0.- Check output to see function call fails
Expected Results
Just value >100 panics and since panic is catched by trap, I expect the subsequent component calls recover to normal state.
Actual Results
Component calls after the panic keep failing, returning "wasm trap: cannot enter component instance"
Versions and Environment
Wasmtime version or commit: cfe17cb1c61658a157e7ad9da2ecbe5f314a2536
Operating system: Ubuntu
Architecture: wasm32-unknown-unknown, wasm32-wasip2 and maybe more
Extra Info
My testing output:
Converted 0 to: Ok(32.0) Converted 32 to: Ok(89.6) Converted 100 to: Ok(212.0) Converted 100.1 to: Err(error while executing at wasm backtrace: 0: 0x2e65 - guest.wasm!__rustc[90fd524071601a38]::__rust_abort 1: 0x3980 - guest.wasm!__rustc[90fd524071601a38]::__rust_start_panic 2: 0x393e - guest.wasm!__rustc[90fd524071601a38]::rust_panic 3: 0x391f - guest.wasm!std::panicking::rust_panic_with_hook::h885a2e0f7cb6094c 4: 0x2f31 - guest.wasm!std::panicking::begin_panic_handler::{{closure}}::hf631a5b49e1d8742 5: 0x2e6b - guest.wasm!std::sys::backtrace::__rust_end_short_backtrace::h055708a75b60b26d 6: 0x349a - guest.wasm!__rustc[90fd524071601a38]::rust_begin_unwind 7: 0x3d6f - guest.wasm!core::panicking::panic_fmt::h3b9ae52b0e452a99 8: 0x3e9 - guest.wasm!<guest::GuestComponent as guest::Guest>::convert_celsius_to_fahrenheit::hf763edc0af92d5f6 9: 0x2f7 - guest.wasm!guest::_export_convert_celsius_to_fahrenheit_cabi::h7eba130e8e72a055 10: 0x427 - guest.wasm!convert-celsius-to-fahrenheit note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information Caused by: wasm trap: wasm `unreachable` instruction executed Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: wasmtime::runtime::trap::from_runtime_box at ./crates/wasmtime/src/runtime/trap.rs:101:39 3: wasmtime::runtime::func::invoke_wasm_and_catch_traps::{{closure}} at ./crates/wasmtime/src/runtime/func.rs:1535:28 4: core::result::Result<T,E>::map_err at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:914:27 5: wasmtime::runtime::func::invoke_wasm_and_catch_traps at ./crates/wasmtime/src/runtime/func.rs:1535:16 6: wasmtime::runtime::func::Func::call_unchecked_raw at ./crates/wasmtime/src/runtime/func.rs:1021:9 7: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func.rs:456:13 8: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl at ./crates/wasmtime/src/runtime/component/func/typed.rs:234:27 9: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call at ./crates/wasmtime/src/runtime/component/func/typed.rs:164:14 10: component::_::<impl component::Convert>::call_convert_celsius_to_fahrenheit at ./examples/component/main.rs:10:1 11: component::main at ./examples/component/main.rs:59:30 12: core::ops::function::FnOnce::call_once at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 13: std::sys::backtrace::__rust_begin_short_backtrace at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18 14: std::rt::lang_start::{{closure}} at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18 15: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/core/src/ops/function.rs:284:21 16: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 17: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 18: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 19: std::rt::lang_start_internal::{{closure}} at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:175:24 20: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 21: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 22: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 23: std::rt::lang_start_internal at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:171:5 24: std::rt::lang_start at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5 25: main 26: <unknown> 27: __libc_start_main 28: _start) Converted 31 to: Err(wasm trap: cannot enter component instance Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: anyhow::kind::Trait::new at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/kind.rs:95:15 3: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func.rs:432:17 4: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call_impl at ./crates/wasmtime/src/runtime/component/func/typed.rs:234:27 5: wasmtime::runtime::component::func::typed::TypedFunc<Params,Return>::call at ./crates/wasmtime/src/runtime/component/func/typed.rs:164:14 6: component::_::<impl component::Convert>::call_convert_celsius_to_fahrenheit at ./examples/component/main.rs:10:1 7: component::main at ./examples/component/main.rs:59:30 8: core::ops::function::FnOnce::call_once at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 9: std::sys::backtrace::__rust_begin_short_backtrace at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18 10: std::rt::lang_start::{{closure}} at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18 11: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/core/src/ops/function.rs:284:21 12: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 13: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 14: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 15: std::rt::lang_start_internal::{{closure}} at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:175:24 16: std::panicking::catch_unwind::do_call at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:589:40 17: std::panicking::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panicking.rs:552:19 18: std::panic::catch_unwind at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/panic.rs:359:14 19: std::rt::lang_start_internal at /rustc/255aa220821c05c3eac7605fce4ea1c9ab2cbdb4/library/std/src/rt.rs:171:5 20: std::rt::lang_start at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5 21: main 22: <unknown> 23: __libc_start_main 24: _start) Converted 50 to: Err(wasm trap: cannot enter component instance Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/backtrace.rs:27:14 1: <T as core::convert::Into<U>>::into at /home/cxiao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:768:9 2: anyhow::kind::Trait::new at /home/cxiao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.93/src/kind.rs:95:15 3: wasmtime::runtime::component::func::Func::call_raw at ./crates/wasmtime/src/runtime/component/func [message truncated]
alexcrichton commented on issue #11086:
Yes this is expected behavior, so I'm going to close this. @xiaocq2001 if you have a suggestion though about where best to document this let us know though!
xiaocq2001 commented on issue #11086:
Thanks for the quick response! So, if I want to make the component work again, I need to re-instantiate it, right? If I re-instantiate the component without re-creating the store, will there be any issues?
alexcrichton commented on issue #11086:
Yes that would work. While not problematic you may want to be aware that a store doesn't GC itself internally ever, meaning that any instances created within a store aren't deallocated until the store is deallocated. If that's a concern for you then you'll want to recreate the store each time, but if that's not a concern there's no issue putting more instances in a store.
xiaocq2001 commented on issue #11086:
Thanks for the clarification.
Regarding instances created within a store, I have a few questions based on the component example. Could you confirm if the following assumptions are correct?
- Local instances created inside
convert_celsius_to_fahrenheitare deallocated if a panic occurs, e.g., a i32 variable.- Global static instances created by
convert_celsius_to_fahrenheitare not deallocated during a panic and will not be accessible ifconvert_celsius_to_fahrenheitis restarted. These instances remain allocated until the entire store is deallocated, e.g., a global static i32 variable.
alexcrichton commented on issue #11086:
Sort of I think, but panics in Rust do not run any destructors in the program at all. They're more like
panic=abortsemantics on native where the program aborts without doing anything else when a panic happens. You mention an i32 variable as a "local instance" but that's not really allocated anywhere. Panics do indeed clean up the stack but that's it, no destructors are run.What I'm saying about instances staying in a store though is more a WebAssembly component instance than anything program-related. The WebAssembly component takes up resources such as tables, linear memories, etc, and all of those stay in the store. These then represent, inside them, program constructs like globals but it's moreso the host embedder resources I wanted to highlight.
xiaocq2001 commented on issue #11086:
Thanks very much.
Last updated: Dec 06 2025 at 06:05 UTC