Skip to content
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

Rust: async exported func cancel safety? #1142

Closed
SupernaviX opened this issue Jan 23, 2025 · 2 comments
Closed

Rust: async exported func cancel safety? #1142

SupernaviX opened this issue Jan 23, 2025 · 2 comments

Comments

@SupernaviX
Copy link

Hello!

I'm contributing to a project which calls async wasmtime exports. Sometimes, those exported functions start failing with the error "wasm trap: cannot enter component instance". I think the issue might be that the generated wasm client isn't cancel-safe.

Here's the relevant snippet from the generated code (generated by wit-bindgen 0.38):

            let _enter = span.enter();
            let callee = unsafe {
                wasmtime::component::TypedFunc::<(u32, &Event,),(Result<Response,HandleError>,)>::new_unchecked(self.handle)
            };
            let(ret0,) = callee.call_async(store.as_context_mut(),(arg0,arg1,)).await?;
            callee.post_return_async(store.as_context_mut()).await?;
            Ok(ret0)

The docs say that if you call TypedFunc's call_async method, you must call post_return_async. In my codebase, the code path which invokes wasm can frequently get cancelled. If this snippet is cancelled during that call to call_async. then it looks like post_return_async will never be called (and there doesn't seem to be a way to recover from that).

Am I right that this code isn't cancel-safe? And if so, is there any way to recover from the cancellation?

@pchickey
Copy link
Contributor

This wit-bindgen repo is for the project that generates guest language bindings for wit. It has a common providence as the version used in wasmtime, but this question is specific to the behavior of wasmtime-wit-bindgen. Could you please reopen this ticket in the wasmtime repo?

@SupernaviX
Copy link
Author

Thank you! Opened bytecodealliance/wasmtime#10088 over there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants