forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
async
call hooks (bytecodealliance#3876)
* Instead of simply panicking, return an error when we attempt to resume on a dying fiber. This situation should never occur in the existing code base, but can be triggered if support for running outside async code in a call hook. * Shift `async_cx()` to return an `Option`, reflecting if the fiber is dying. This should never happen in the existing code base, but is a nice forward-looking guard. The current implementations simply lift the trap that would eventually be produced by such an operation into a `Trap` (or similar) at the invocation of `async_cx()`. * Add support for using `async` call hooks. This retains the ability to do non-async hooks. Hooks end up being implemented as an async trait with a handler call, to get around some issues passing around async closures. This change requires some of the prior changes to handle picking up blocked tasks during fiber shutdown, to avoid some panics during timeouts and other such events. * More fully specify a doc link, to avoid a doc-building error. * Revert the use of catchable traps on cancellation of a fiber; turn them into expect()/unwrap(). The justification for this revert is that (a) these events shouldn't happen, and (b) they wouldn't be catchable by wasm anyways. * Replace a duplicated check in `async` hook evaluation with a single check. This also moves the checks inside of their respective Async variants, meaning that if you're using an async-enabled version of wasmtime but using the synchronous versions of the callbacks, you won't pay any penalty for validating the async context. * Use `match &mut ...` insead of `ref mut`. * Add some documentation on why/when `async_cx` can return None. * Add two simple test cases for async call hooks. * Fix async_cx() to check both the box and the value for current_poll_cx. In the prior version, we only checked that the box had not been cleared, but had not ensured that there was an actual context for us to use. This updates the check to validate both, returning None if the inner context is missing. This allows us to skip a validation check inside `block_on`, since all callers will have run through the `async_cx` check prior to arrival. * Tweak the timeout test to address PR suggestions. * Add a test about dropping async hooks while suspended Should help exercise that the check for `None` is properly handled in a few more locations. Co-authored-by: Alex Crichton <[email protected]>
- Loading branch information
1 parent
923faaf
commit 6a60e83
Showing
5 changed files
with
369 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.