Stream: wasmtime

Topic: Missing stack trace in trap


view this post on Zulip Peter Vetere (Jun 20 2022 at 20:29):

I'm seeing some peculiar behavior in Wasmtime around stack trace generation when a trap occurs. There appear to be some runtime environments where stack traces do not get generated.

Specifically, I have a Python program that embeds Wasmtime (using the Wasmtime Python API). It runs a Rust-sourced Wasm module that causes a trap by trying to unwrap a None value. When I run it on my local system, an error message and stack trace are both present in the trap object's message. However, when I run the same program in a Docker container, the only thing in the message is the error:

wasm trap: wasm `unreachable` instruction executed

Looking through the Wasmtime source code, I see a comment in trap.rs that says:

    /// This function return an `Option` of a list of frames to indicate that
    /// wasm frames are not always available. Frames will never be available if
    /// backtraces are disabled via
    /// [`Config::wasm_backtrace`](crate::Config::wasm_backtrace). Frames will
    /// also not be available for freshly-created traps. WebAssembly frames are
    /// currently only captured when the trap reaches wasm itself to get raised
    /// across a wasm boundary.

However, none of the described scenarios appear to apply in my case, at least on the surface. Is there an OS package I might need to install in the container, or perhaps some other specific environmental requirement to be aware of when running in a container? An additional data point is that I am able to manually inspect my program's stack in a debugger in the same container, so it seems that the information is at least available.

Thank you.
Pete

view this post on Zulip Alex Crichton (Jun 20 2022 at 20:58):

Wasmtime uses the system libunwind (or some variation thereof) to generate a backtrace so the difference here is likely in either how something like Python is compiled or the actual code that's acquring the backtrace (e.g. the implementation of _Unwind_Backtrace). This probably isn't related to Wasmtime configuration and is rather related to system/compile things. If you can share the Docker reproduction though I can try to help dig in a bit

view this post on Zulip Peter Vetere (Jun 20 2022 at 21:11):

Thanks! I'll put together a simple test case and follow-up here.


Last updated: Nov 22 2024 at 16:03 UTC