Skip to content

Conversation

@alexcrichton
Copy link
Member

No description provided.

dicej and others added 4 commits September 9, 2025 08:46
…ance#11625)

* support non-async `{stream,future}.cancel-{read,write}`

During my earlier stream API refactoring, I had forgotten to support or test
synchronous cancellation; this commit does both.  In the process, I realized the
future API ought to be updated to support blocking cancellation just like the
stream API, so I made that change as well.

This also adds `{Source,Destination}::reborrow` functions, allowing instances of
those types to be reborrowed, such that they may be passed as parameters but
also used again.

Note that I had to move some functions from `impl ConcurrentState` to `impl
Instance` in order to access the store and suspend the current fiber when
synchronously cancelling.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* reduce code duplication

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
…ytecodealliance#11645)

* support and test synchronous `{stream,future}.cancel-{read,write}`

Previously, we only supported async calls to those intrinsics; now we support
blocking, synchronous calls as well.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* update future-read.wast test

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* refactor(p3-http): use trappable errors

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* feat(p3-http): implement `content-length` handling

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor(p3-http): remove a few resource utilities

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* remove unused test import

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* fix(p3-http): close stream handles on drop

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* test(p3-http): stream responses back

This is something we've been doing in wasip3, but I forgot to port this
over

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* doc(p3-http): add missing docs, internalize more, simplify

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor(p3-http): extract `Body::consume`

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor(p3-http): clean-up `content-length` error reporting

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor(p3-http): drop elided lifetime

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* fix(p3-http): avoid guest body deadlock hazard

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor(p3-http): add more docs, clean-up

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* doc(p3-http): add more docs

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* fix(p3-http): rework result future handling

Most importantly this avoids a race condition between `content-length` error observed by `GuestBody`
and hyper I/O driver

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* add new imports after rebase

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* clean-up `poll_consume`

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* assert content-length `handle` results

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* relax `content_length` test `handle` assert

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
* p3: refactor future producers/consumers

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* p3-http: tie lifetime of the spawned task to the bodies

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* p3-http: improve docs

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@alexcrichton alexcrichton requested review from a team as code owners September 9, 2025 15:46
@alexcrichton alexcrichton requested review from dicej and removed request for a team September 9, 2025 15:46
@alexcrichton
Copy link
Member Author

cc @rvolosatovs this failure looks like a spurious flake in wasi-http tests (I can retry it but I don't want to lose it either):

---- p3::p3_http_outbound_request_content_length stdout ----
worker failed with error error from user's Body stream

Caused by:
    0: error reading a body from connection
    1: end of file before message length reached
Error: failed to call `wasi:cli/run#run`

Caused by:
    0: error while executing at wasm backtrace:
           0:  0x68d1c - panic_abort::__rust_start_panic::abort::hfa521bba89ce5759
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/panic_abort/src/lib.rs:113:17
                       - __rustc[95feac21a9532783]::__rust_start_panic
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/panic_abort/src/lib.rs:49:9
           1:  0x68b8d - __rustc[95feac21a9532783]::rust_panic
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:894:25
           2:  0x68b60 - std::panicking::rust_panic_with_hook::hc20fbdbadfcc1625
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:858:5
           3:  0x67b76 - std::panicking::begin_panic_handler::{{closure}}::h1237330613601c3b
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:706:13
           4:  0x67ae2 - std::sys::backtrace::__rust_end_short_backtrace::h207b568e8da931a1
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:168:18
           5:  0x684f3 - __rustc[95feac21a9532783]::rust_begin_unwind
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
           6:  0x6d541 - core::panicking::panic_fmt::he093f8ef6966d6c7
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
           7:  0x6f37d - core::result::unwrap_failed::h1bc014930691ddf4
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1704:5
           8:   0xacac - core::result::Result<T,E>::expect_err::h4dc44849308773ac
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1172:22
           9:  0x24154 - <p3_http_outbound_request_content_length::Component as test_programs::p3::exports::wasi::cli::run::Guest>::run::{{closure}}::h667ad4c0ebe40218
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/bin/p3_http_outbound_request_content_length.rs:113:23
          10:   0x6462 - test_programs::p3::exports::wasi::cli::run::_export_run_cabi::{{closure}}::h09fcbd8e6973714c
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/p3/mod.rs:4:1
          11:  0x5b72d - <core::pin::Pin<P> as core::future::future::Future>::poll::h245dcf4b3ca770e1
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/future/future.rs:124:9
                       - <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next::hcea85e06fb1b7f9f
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/stream/futures_unordered/mod.rs:528:17
          12:  0x5adec - futures_util::stream::stream::StreamExt::poll_next_unpin::h1fd061b6541c9252
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/stream/stream/mod.rs:1638:9
                       - wit_bindgen::rt::async_support::FutureState::poll::{{closure}}::h530bc3620a250b26
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:182:28
                       - wit_bindgen::rt::async_support::FutureState::with_p3_task_set::h7bb4c3253b380010
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:237:9
                       - wit_bindgen::rt::async_support::FutureState::poll::h5ea42f12fe68d819
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:171:9
                       - wit_bindgen::rt::async_support::FutureState::callback::h029d8768fc21ec15
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:151:9
          13:  0x5b112 - wit_bindgen::rt::async_support::callback::h735e0c385c706a91
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:400:26
          14:  0x2951d - test_programs::p3::exports::wasi::cli::run::__callback_run::h2122a0f968825060
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/p3/mod.rs:4:1
          15:  0x24516 - [callback][async-lift]wasi:cli/run@0.3.0-rc-2025-08-15#run
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/bin/p3_http_outbound_request_content_length.rs:9:1
    1: wasm trap: wasm `unreachable` instruction executed


failures:
    p3::p3_http_outbound_request_content_length

@rvolosatovs
Copy link
Member

cc @rvolosatovs this failure looks like a spurious flake in wasi-http tests (I can retry it but I don't want to lose it either):

---- p3::p3_http_outbound_request_content_length stdout ----
worker failed with error error from user's Body stream

Caused by:
    0: error reading a body from connection
    1: end of file before message length reached
Error: failed to call `wasi:cli/run#run`

Caused by:
    0: error while executing at wasm backtrace:
           0:  0x68d1c - panic_abort::__rust_start_panic::abort::hfa521bba89ce5759
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/panic_abort/src/lib.rs:113:17
                       - __rustc[95feac21a9532783]::__rust_start_panic
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/panic_abort/src/lib.rs:49:9
           1:  0x68b8d - __rustc[95feac21a9532783]::rust_panic
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:894:25
           2:  0x68b60 - std::panicking::rust_panic_with_hook::hc20fbdbadfcc1625
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:858:5
           3:  0x67b76 - std::panicking::begin_panic_handler::{{closure}}::h1237330613601c3b
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:706:13
           4:  0x67ae2 - std::sys::backtrace::__rust_end_short_backtrace::h207b568e8da931a1
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/sys/backtrace.rs:168:18
           5:  0x684f3 - __rustc[95feac21a9532783]::rust_begin_unwind
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
           6:  0x6d541 - core::panicking::panic_fmt::he093f8ef6966d6c7
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
           7:  0x6f37d - core::result::unwrap_failed::h1bc014930691ddf4
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1704:5
           8:   0xacac - core::result::Result<T,E>::expect_err::h4dc44849308773ac
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/result.rs:1172:22
           9:  0x24154 - <p3_http_outbound_request_content_length::Component as test_programs::p3::exports::wasi::cli::run::Guest>::run::{{closure}}::h667ad4c0ebe40218
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/bin/p3_http_outbound_request_content_length.rs:113:23
          10:   0x6462 - test_programs::p3::exports::wasi::cli::run::_export_run_cabi::{{closure}}::h09fcbd8e6973714c
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/p3/mod.rs:4:1
          11:  0x5b72d - <core::pin::Pin<P> as core::future::future::Future>::poll::h245dcf4b3ca770e1
                           at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/future/future.rs:124:9
                       - <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next::hcea85e06fb1b7f9f
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/stream/futures_unordered/mod.rs:528:17
          12:  0x5adec - futures_util::stream::stream::StreamExt::poll_next_unpin::h1fd061b6541c9252
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/stream/stream/mod.rs:1638:9
                       - wit_bindgen::rt::async_support::FutureState::poll::{{closure}}::h530bc3620a250b26
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:182:28
                       - wit_bindgen::rt::async_support::FutureState::with_p3_task_set::h7bb4c3253b380010
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:237:9
                       - wit_bindgen::rt::async_support::FutureState::poll::h5ea42f12fe68d819
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:171:9
                       - wit_bindgen::rt::async_support::FutureState::callback::h029d8768fc21ec15
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:151:9
          13:  0x5b112 - wit_bindgen::rt::async_support::callback::h735e0c385c706a91
                           at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wit-bindgen-0.45.0/src/rt/async_support.rs:400:26
          14:  0x2951d - test_programs::p3::exports::wasi::cli::run::__callback_run::h2122a0f968825060
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/p3/mod.rs:4:1
          15:  0x24516 - [callback][async-lift]wasi:cli/run@0.3.0-rc-2025-08-15#run
                           at /home/runner/work/wasmtime/wasmtime/crates/test-programs/src/bin/p3_http_outbound_request_content_length.rs:9:1
    1: wasm trap: wasm `unreachable` instruction executed


failures:
    p3::p3_http_outbound_request_content_length

The fix is not entirely obvious, in fact I'm quite confused how the transmit future could have not failed while the handle one did. I'll have to reproduce this locally

@github-actions github-actions bot added wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself labels Sep 9, 2025
alexcrichton and others added 2 commits September 9, 2025 11:00
…iance#11655)

Previously, we were unconditionally deleting the callee subtask once it returned
a value to a sync-lowered call, but that's only appropriate if the subtask has
exited.  Otherwise, it needs to keep running and only be deleted once it
actually exits.

Thanks to Luke for the `sync-streams.wast` test that uncovered this, which I've
copied from the `component-model` repo.

This also makes a couple of debug logging tweaks that proved useful while
investigating the above issue.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@alexcrichton alexcrichton enabled auto-merge (squash) September 9, 2025 18:01
@alexcrichton alexcrichton merged commit 5b4ef94 into bytecodealliance:release-37.0.0 Sep 9, 2025
168 checks passed
@alexcrichton alexcrichton deleted the more-backports branch September 9, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants