Open redoC-A2k opened 4 months ago
You can also have a look here - https://github.com/bytecodealliance/wasmtime/issues/8670#issuecomment-2124871948 That's my actual use case .
Thanks for reporting this, @redoC-A2k. Yes, I understand what you're trying to do -- thanks for the thorough explanation.
The component model currently does not allow calling a guest export from a host function called by the guest, and isyswasfa
does not relax that restriction, unfortunately. Also, isyswasfa
does not currently support the host calling more than one guest export concurrently, even at the top level of the program; although that's just a limitation of the current implementation rather than a fundamental restriction.
I think we could support this use case if we were to update the isyswasfa
implementation to allow multiple concurrent calls to guest exports. I don't think that would be terribly difficult, but I haven't tried to tackle it yet because it's challenging to do in an ergonomic way. Currently, the generated host bindings for functions return a Future
which owns the an exclusive reference to the Wasmtime Store
. We'd need to change that to something that only requires an exclusive reference when polled, i.e. something similar to a Future
, but not the same thing.
Anyway, I'm sure we could find some way to make that work, and if we did, we could support your use case by allowing the host embedder to make a concurrent call to a guest export such that the actual call into the guest is deferred to the top-level event loop. That would allow you to make the call from the host import without violating the reentrancy rule, but still allow the guest to "wait for itself".
That said, I don't expect I'll implement all that in isyswasfa
since I've shifted focus to upstreaming component model async support to Wasmtime. I'll keep this use case in mind for that upstream work, though.
I modified the round trip example like follows but I am getting error -
wasm trap: cannot enter component instance
I added below two static variables -
Modified async fn round_trip
Modified wit file for round_trip
interface demo { boo: func(s: string) -> string; }
world round-trip { import wasi:clocks/monotonic-clock@0.2.0; import baz; export demo; export baz; }
Modified guest implementation for wit file
[async_trait(?Send)]
impl demo::Guest for Component { async fn boo(s : String) -> String { println!("Guest run now"); format!("{s} - exited guest again") } }
I Hope you have understood what I want to achieve . Basically what I want is to again enter the component (which is in execution) and run some code then return the result of that to the first function .