Stream: git-wasmtime

Topic: wasmtime / issue #8943 wasm trap: cannot enter component ...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2024 at 13:02):

nerdachse opened issue #8943:

Hey there!

Similar to #8670 (which I read), I have a problem with calling multiple functions of a wasm component.

        let info_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/info")
                .expect(&format!("plugin@{path:?} to have info instance"));
            match register.typed_func::<(), (PluginInfo,)>("info") {
                Ok(info) => info,
                Err(e) => {
                    eprintln!("plugin@{path:?} does not have an info function: {e}!");
                    continue;
                }
            }
        };

        let info = info_func.call(&mut store, ());
        println!("plugin@{path:?}: {info:?}");

        // Scope the borrow of &mut store to limit its lifetime
        let init_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/register")
                .expect(&format!("plugin@{:?} to have register instance", path));
            match register.typed_func::<(), (String,)>("init") {
                Ok(init) => init,
                Err(e) => {
                    eprintln!("plugin@{:?} does not have an init function: {}!", path, e);
                    continue;
                }
            }
        };

        // Now call the init function after the borrow from exports has ended
        let result = init_func.call(&mut store, ()).expect("init to be callable");
        println!("plugin@{:?} result of init: {:?}", path, result);

gives me:

thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instance

Now I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.

As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.

I use wasmtime 22.0.0 and wasmtime_wasi 22.0.0 btw.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2024 at 13:02):

nerdachse edited issue #8943:

Hey there!

Similar to #8670 (which I read), I have a problem with calling multiple functions of a wasm component.

        let info_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/info")
                .expect(&format!("plugin@{path:?} to have info instance"));
            match register.typed_func::<(), (PluginInfo,)>("info") {
                Ok(info) => info,
                Err(e) => {
                    eprintln!("plugin@{path:?} does not have an info function: {e}!");
                    continue;
                }
            }
        };

        let info = info_func.call(&mut store, ());
        println!("plugin@{path:?}: {info:?}");

        // Scope the borrow of &mut store to limit its lifetime
        let init_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/register")
                .expect(&format!("plugin@{:?} to have register instance", path));
            match register.typed_func::<(), (String,)>("init") {
                Ok(init) => init,
                Err(e) => {
                    eprintln!("plugin@{:?} does not have an init function: {}!", path, e);
                    continue;
                }
            }
        };

        // Now call the init function after the borrow from exports has ended
        let result = init_func.call(&mut store, ()).expect("init to be callable");
        println!("plugin@{:?} result of init: {:?}", path, result);

gives me:

thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instance

Now I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.

As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.

I use wasmtime 22.0.0 and wasmtime_wasi 22.0.0 btw.
```[tasklist]

Tasks

~~~

view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2024 at 13:02):

nerdachse edited issue #8943:

Hey there!

Similar to #8670 (which I read), I have a problem with calling multiple functions of a wasm component.

        let info_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/info")
                .expect(&format!("plugin@{path:?} to have info instance"));
            match register.typed_func::<(), (PluginInfo,)>("info") {
                Ok(info) => info,
                Err(e) => {
                    eprintln!("plugin@{path:?} does not have an info function: {e}!");
                    continue;
                }
            }
        };

        let info = info_func.call(&mut store, ());
        println!("plugin@{path:?}: {info:?}");

        // Scope the borrow of &mut store to limit its lifetime
        let init_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/register")
                .expect(&format!("plugin@{:?} to have register instance", path));
            match register.typed_func::<(), (String,)>("init") {
                Ok(init) => init,
                Err(e) => {
                    eprintln!("plugin@{:?} does not have an init function: {}!", path, e);
                    continue;
                }
            }
        };

        // Now call the init function after the borrow from exports has ended
        let result = init_func.call(&mut store, ()).expect("init to be callable");
        println!("plugin@{:?} result of init: {:?}", path, result);

gives me:

thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instance

Now I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.

As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.

I use wasmtime 22.0.0 and wasmtime_wasi 22.0.0 btw.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 12 2024 at 15:25):

alexcrichton commented on issue #8943:

You're missing a call to TypedFunc::post_return here which should be mentioned in the TypedFunc::call documentation as well. If possible I'd recommend using bindgen! if it works for your use case.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 11 2024 at 19:15):

nerdachse closed issue #8943:

Hey there!

Similar to #8670 (which I read), I have a problem with calling multiple functions of a wasm component.

        let info_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/info")
                .expect(&format!("plugin@{path:?} to have info instance"));
            match register.typed_func::<(), (PluginInfo,)>("info") {
                Ok(info) => info,
                Err(e) => {
                    eprintln!("plugin@{path:?} does not have an info function: {e}!");
                    continue;
                }
            }
        };

        let info = info_func.call(&mut store, ());
        println!("plugin@{path:?}: {info:?}");

        // Scope the borrow of &mut store to limit its lifetime
        let init_func = {
            let mut exports: wasmtime::component::Exports = plugin.exports(&mut store);
            let mut register = exports
                .instance("test:guest/register")
                .expect(&format!("plugin@{:?} to have register instance", path));
            match register.typed_func::<(), (String,)>("init") {
                Ok(init) => init,
                Err(e) => {
                    eprintln!("plugin@{:?} does not have an init function: {}!", path, e);
                    continue;
                }
            }
        };

        // Now call the init function after the borrow from exports has ended
        let result = init_func.call(&mut store, ()).expect("init to be callable");
        println!("plugin@{:?} result of init: {:?}", path, result);

gives me:

thread 'main' panicked at src/main.rs:121:53:
init to be callable: wasm trap: cannot enter component instance

Now I understand the problem but in #8670 it was said that there could be another solution for this and I wonder what this could be. First attempt was to just iterate again, but apart from being non-optimal it's not enough to solve the problem.

As I plan on making a plugin system and sending events to interested plugins all the time, I wonder whether that's even feasible now.

I use wasmtime 22.0.0 and wasmtime_wasi 22.0.0 btw.


Last updated: Dec 23 2024 at 12:05 UTC