Add ResourceLimiterAsync, which can yield until resource is available#3393
Conversation
Subscribe to Label Actioncc @fitzgen, @peterhuene DetailsThis issue or pull request has been labeled: "fuzzing", "wasmtime:api"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
1e14251 to
7d0611b
Compare
alexcrichton
left a comment
There was a problem hiding this comment.
Looking good to me! If you're up for it I think it would also be interesting to have tests which panic! in the memory growth (either in the async or sync version) from the custom trait implementation which then asserts that the panic can be caught from the other side of wasm and handled.
edd3b8e to
d3deaae
Compare
idk why this didnt work in the old factoring! but im glad it does
alexcrichton
left a comment
There was a problem hiding this comment.
All looks good to me! A few minor things I might also ask for:
- Doc updates to the blocking methods that they can panic for async stores with an async limiter configured
- Could you add a test where the async-ness is exercised as well? I noticed most of them using the async trait were just async conditions, but could there be one which also sleeps or synchronizes with some other task or something like that?
alexcrichton
left a comment
There was a problem hiding this comment.
👍
Ok final nit I forgot from earlier, can you add this to the #[cfg]'d APIs so the feature requirement is rendered with rustdoc? Other than that looks good to go!
#[cfg_attr(nightlydoc, doc(cfg(feature = "async")))]
This PR:
ResourceLimiter's definition fromwasmtime_runtimetowasmtimeResourceLimiterAsync, which is just like aResourceLimiterexcept thememory_growingandtable_growingmethods areasync(via#[async_trait]). This is so that async embeddings of wasmtime can handle memory or table growing byawaiting for a resource to be available.ResourceLimiterAsyncmethods to await inside memory & table grows, we need to add async variants ofMemory::new,Memory::grow,Table::new, andTable::grow. These variants are not required for all asyncStores, only for stores which are given aStore::limiter_async. So, this won't break any existing code.ResourceLimitertraits now gettable_grow_failed, which corresponds tomemory_grow_failed. Better to just get this over with now than have to add it in later.I had to restructure a fair bit of the interface between runtime and wasmtime for this PR, including extending the
wasmtime_runtime::Storetrait, and changing the error type passed between them toanyhow::Errorinstead ofBox<dyn std::error::Error + Send + Sync>.Additionally, both
ResourceLimiters are now safer: wasmtime_runtime now catches any panics that occur from the user's impl of the traits.