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

Interruptible timeout in wasm #8687

Closed
redoC-A2k opened this issue May 23, 2024 · 4 comments
Closed

Interruptible timeout in wasm #8687

redoC-A2k opened this issue May 23, 2024 · 4 comments

Comments

@redoC-A2k
Copy link

I want to wait / sleep or run a function after timeout of some seconds in wasm32-wasi component ? But I want that to be cancellable .
I tried doing this - https://stackoverflow.com/a/70121550 But I got error - failed to spawn thread: Error { kind: Unsupported, message: "operation not supported on this platform" } on spawning thread , I have tried compiling my rust to wasm32-wasip1-threads and on host I have make sure to enable wasm_threads support by config.wasm_threads(true).

What else do I need to do ?

@alexcrichton
Copy link
Member

If you're the host then you can use Wasmtime's async support in conjunction with epochs or fuel to interrupt WebAssembly that's currently executing.

If you're the guest then the main way to block right now is through the "poll"-style interfaces which have a timeout parameter. You'll need to coordinate within the guest to ensure that this timeout is configured accordingly.

@redoC-A2k
Copy link
Author

redoC-A2k commented May 23, 2024

Could you explain more please ? If you can provide some documentations and demo github examples that will be great . I was expecting on guest side interrupt but I saw here - https://github.com/dicej/component-async-demo that @dicej has been using his local fork of wasmtime and other wasm tools (wit-bindgen , wasm-tools , wasmtime-wasi) . So I thought may be the async thing is not ready and not available right now . Also I am using right now 19 version of wasmtime and related tools (wasmtime-wasi , wasm-tools and so on) although I can try upgrading it to latest version if needed

@dicej
Copy link
Contributor

dicej commented May 23, 2024

Implementing a cancellable timeout should be doable with WASI 0.2 using wasi:io/poll (i.e. you shouldn't need any of the WASI 0.3 stuff I'm currently working on, and that's not ready for production use yet anyway).

The main question to answer is: what event(s) should trigger cancellation? That will determine what kind of pollables you'll pass to the poll function in addition to the monotonic-clock.subscribe_duration pollable that represents the timeout. Should it be readability on a TCP socket? Progress on an outgoing HTTP request? Something else? All of the above?

@alexcrichton
Copy link
Member

I believe the question here has been answered so I'm going to close, but feel free to comment and/or open a new issue with other questions.

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

3 participants