-
Notifications
You must be signed in to change notification settings - Fork 25
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
Is it intentional that bi-directional communication is partially supported? #24
Comments
Thanks for reporting this and the detailed explanation! This bi-directional communication with several back and forth hops absolutely should be supported. I'll take a look at this. |
warning, these are just drive-by thoughts from someone only using go for <1.5years, and also I work on wazero. I'm not sure any CGO lib would be able to propagate go context.. if anything some pointer magic and the lib would be very aware of it. I've not seen anything in the rust projects (wasmer, wasmtime) that would do it. An alternative could be to change wapc's callback apis to add a u64 param and require it as a sort of correlation context parameter. you could for example store an unsafe pointer of a context.Context between calls that way, and look it up. A less api effecting way could be to use something like go-eden for context-storage. When CGO is already in use, it claims to have an efficient mechanism that internally correlates data based on a goroutine ID. If you use that, be careful to not make it a required dep for all wasm runtimes and also watch for supported arch/os because the non-CGO alternative is documented (and looks) expensive https://github.com/go-eden/routine/blob/b65d4d238e09c18ba6470bb5731f514b8068392b/routine_goid.go#L63 hope this helps! |
@cuongvo would you be ok with contributing (even pasting here) a failing unit test for the flow? One that would go into the main test file? |
Apologies, just saw this. Sure, I can provide a failing unit test to demonstrate this. |
@codefromthecrypt Here's a commit that shows the error: d60104a I removed
|
I hit a similar problem and found that |
Per the waPC specifications it looks like after the guest is invoked initially, the supported flow is the guest is allowed to make 0..N
__host_call
before returning.There's another flow, where communication is bi-directional, or where multiple
__guest_call
s occur from a singleinvoke
:__guest_call
This flow currently fails for the final
__guest_call
inwasmer
(assumption is it also fails inwasmtime
), but works forwazero
. This is due to the use ofinvokeContext
. Inwasmer
/wasmtime
this is a pointer stored on the shared instance and the response copied to it (here), but the return value ofinvoke
is read from the originalinvokeContext
(here). With multiple__guest_call
in a single flow, the shared context is replaced. The output is copied to theinvokeContext
of the previous__guest_call
and the final__guest_call
in the chain returns a zero value.wazero
supports this flow since each__guest_call
viainvoke
usingwazero
gets its own context, not a shared context on the instance (here).Whew, with that out of the way. Is the above bi-directional flow supported? If not, should it be supported and the implementation for
wasmer
andwasmtime
changed to allow it?The text was updated successfully, but these errors were encountered: