tetratelabs / wazero

wazero: the zero dependency WebAssembly runtime for Go developers

Home Page:https://wazero.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can a Runtime be reused in parallel and across multiple mutually-untrusted modules?

cube2222 opened this issue · comments

I've tried to find this information in the docs, and comments in the code, but I couldn't find anything clarifying this. For full context, I'm using the Compiler engine with the latest wazero release, and using WASI with it.

Question 1: Can a single runtime be used concurrently across many goroutines? Can I compile modules in parallel, and then instantiate those compiled modules in parallel?

Question 2: I'm building a system where users can provide their own wasm modules for me to run. A single instance might need to simultaneously run modules for multiple users. Is it safe to instantiate modules from multiple users (who don't trust each-other, and could be trying to attach each-other) at the same time on a single Runtime?

Or should separate runtimes be used in these cases?

Question 1: yes.

You can definitely instantiate concurrently, and I'm pretty sure you can compile concurrently as well.

Question 2: no.

Use different runtimes. If one module exports its memory, another can import it. If one module exports functions, another can import them. Etc.

Share the compilation cache. Maybe. If you're sure it's useful to do so.

Thanks a lot for the prompt response, that makes sense!