runtime: convert CallInterceptor to async for chain-subscriber back-pressure#27
Merged
Conversation
…ressure Theater's chain-subscription redesign (theater PR #105) needs the chain-emission path to apply real back-pressure on slow subscribers — StateChain::add_typed_event must .await the per-subscriber Sender::send instead of try_send. That requires the calling context (CallInterceptor's methods) to be async. Trait change: - CallInterceptor methods are now async, declared via #[async_trait]. - This is a breaking change → packr should go out as 0.7.0. Call-site updates: - Async host bridges (func_async, func_async_result, AsyncInstance call_with_value_async) .await the interceptor directly. - Sync host bridges (func_typed, func_typed_result) drive the future via a new block_on_interceptor helper: tokio::task::block_in_place + Handle::current().block_on(...). When an interceptor is installed on the sync paths, a tokio multi-thread runtime is required (documented on the trait). New deps: - async-trait 0.1 - tokio 1 with rt-multi-thread (promoted from dev-dep) Regression test: - tests/interceptor_backpressure.rs spins up an interceptor whose after_import .awaits on an mpsc cap=1. A wasm export calls a host import twice; verify the second after_import (and the second wasm-side return) block until the channel drains.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Theater's chain-subscription redesign (theater #105) makes the chain the source of truth for event delivery. To get real producer back-pressure — a slow subscriber gating the wasm-side host-call rate —
StateChain::add_typed_eventneeds to.awaiteach subscriber'sSender::send(...)instead oftry_send'ing and dropping on overflow.That requires the calling context (
CallInterceptor's methods, which theater hooksadd_typed_eventinto) to be async. This PR converts the trait.Trait change (breaking → 0.7.0)
CallInterceptormethods are nowasync fn, declared via#[async_trait]:Bridge updates
func_async,func_async_result,AsyncInstance::call_with_value_async).awaitthe interceptor directly — this is the path theater uses and the one that gets the back-pressure win.func_typed,func_typed_result) drive the future via a newblock_on_interceptorhelper usingtokio::task::block_in_place+Handle::current().block_on(...). When an interceptor is installed on the sync paths, a tokio multi-thread runtime is required — documented on the trait.New deps
async-trait = "0.1"(regular dep)tokiowithrt-multi-thread(was dev-only, now also a regular dep — needed for the sync-bridge block-on path)Regression test
tests/interceptor_backpressure.rs— an interceptor whoseafter_import.awaits on a boundedmpsc::Sender<Value>of capacity 1. A wasm export calls a host import twice. After 200ms the test asserts:after_importfutures startedsend)Then the test drains the channel and verifies the wasm task completes with the expected result. This is the back-pressure property theater's PR #105 depends on.
Migration for downstream impls
Both known impls (theater's
RecordingInterceptorandReplayRecordingInterceptor) need: add#[async_trait]attr, mark methodsasync,.awaitany internal calls that became async. Theater's patch is already prototyped and queued to land the moment 0.7.0 is on crates.io.Release expectations
Trait change is breaking → bump to 0.7.0 on merge (via
nix run .#release -- minor).Test plan
cargo test --workspace(all green, including new back-pressure test)cargo test -p packr-abi --features derivecargo clippy --workspace -- -D warningscargo fmt --all -- --check