Skip to content

Conversation

@rvolosatovs
Copy link
Member

@rvolosatovs rvolosatovs commented Sep 9, 2025

Closes #11656

We paired with @alexcrichton yesterday debugging this (thank you, @alexcrichton!) and here's the summary of what we've found out:
The reason for the flakiness was an issue in implementation of the test HTTP server logic - short write of the 2nd connection would sometimes cause an error and the 3rd connection would fail to get established, since the server would stop accepting connections.
The reason for this is that there is a race condition for the "short write" case in which the client might not even have started sending the request body to the server yet when the error is caught by the consumer and consequently the I/O driver task is dropped. The cases where the body was not started to be transmitted yet would be treated as success by Hyper and so the 3rd connection would be accepted, however in the rare cases where the request body has already started being streamed, connection handling would fail server-side due to the short write, aborting the accept loop and causing "connection refused" error in the guest for the 3rd connection never triggering the content-length check for the 3rd case and therefore causing a panic on the transmit.expect_err, since from wasi:http perspective transmission future did not encounter errors as it has never even began. To address the last part, I've also pushed db3cbac to make sure content-length check happens early and even if the GuestBody is already dropped by the time guest is trying to write

In this PR I've also:

  • added content-length validation for requests carrying bodies originating from the host
  • did some refactoring of the guest body functionality
  • added a bit more docs

@rvolosatovs rvolosatovs force-pushed the fix/flaky-content-length-test branch 2 times, most recently from c2d00f7 to 9fa428c Compare September 9, 2025 17:59
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
prtest:full

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs force-pushed the fix/flaky-content-length-test branch from 848ff19 to 43fca87 Compare September 10, 2025 09:33
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs marked this pull request as ready for review September 10, 2025 10:29
@rvolosatovs rvolosatovs requested review from a team as code owners September 10, 2025 10:29
@rvolosatovs rvolosatovs requested review from alexcrichton and fitzgen and removed request for a team and fitzgen September 10, 2025 10:29
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs force-pushed the fix/flaky-content-length-test branch from 15d2f9b to a8599c2 Compare September 10, 2025 11:11
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs
Copy link
Member Author

rvolosatovs commented Sep 10, 2025

I've been working on some refactoring and addition of content-length validation for requests carrying bodies originating from the host. Since it's all related to content-length, I went ahead and just pushed it to this PR to simplify review/merge process

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs changed the title fix(p3-http): flaky content-length test p3-http: fix flaky content-length test, rework Sep 10, 2025
@rvolosatovs rvolosatovs changed the title p3-http: fix flaky content-length test, rework p3-http: rework content-length handling Sep 10, 2025
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs added this pull request to the merge queue Sep 10, 2025
Merged via the queue into bytecodealliance:main with commit 5a2860c Sep 10, 2025
168 checks passed
@rvolosatovs rvolosatovs deleted the fix/flaky-content-length-test branch September 10, 2025 14:43
@alexcrichton alexcrichton moved this to Done in Ship WASIp3 Sep 10, 2025
alexcrichton pushed a commit to alexcrichton/wasmtime that referenced this pull request Sep 11, 2025
* p3-http: correctly handle `result` future cancellation

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

* p3-http: restructure the `content-length` test a bit

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

* test(http): keep accepting connections after errors

prtest:full

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

* test(p3-http): assert `handle` error on exceeding `content-length`

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

* p3-http: perform `content-length` check early

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

* test(p3-http): account for `handle` race condition

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

* refactor(http): reuse `get_content_length`

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

* p3-http: check `content-length` for host bodies

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

* doc(p3-http): call out that host bodies are not validated

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

* p3-http: refactor body size error send

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

* fix(p3-http): do not rely on `Drop` for host body check

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

* doc(p3-http): ensure non-default send request is documented

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

* doc(p3-http): correct `send_request` doc

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

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
alexcrichton added a commit that referenced this pull request Sep 11, 2025
* p3-http: rework `content-length` handling (#11658)

* p3-http: correctly handle `result` future cancellation

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

* p3-http: restructure the `content-length` test a bit

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

* test(http): keep accepting connections after errors

prtest:full

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

* test(p3-http): assert `handle` error on exceeding `content-length`

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

* p3-http: perform `content-length` check early

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

* test(p3-http): account for `handle` race condition

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

* refactor(http): reuse `get_content_length`

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

* p3-http: check `content-length` for host bodies

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

* doc(p3-http): call out that host bodies are not validated

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

* p3-http: refactor body size error send

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

* fix(p3-http): do not rely on `Drop` for host body check

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

* doc(p3-http): ensure non-default send request is documented

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

* doc(p3-http): correct `send_request` doc

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

---------

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

* return `TaskExit` future from `[Typed]Func::call_concurrent` (#11662)

* return `TaskExit` future from `[Typed]Func::call_concurrent`

In addition to returning the value produced by the callee, these functions now
also return a `TaskExit` future which resolves once the subtask (and any
transitively-created subtasks) have exited.  This partially addresses #11600;
the next step will be to add a `wasmtime-wit-bindgen` option to expose the
`TaskExit` value in generated bindings.

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

* address review feedback

`TaskExit` now has an `async fn block` instead of closing over an `impl
AsAccessor` and implementing `Future`.

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

---------

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

* Update to wasm-tools 239 (#11660)

Changes include:

* `async` option on some CM intrinsics renamed to `cancellable`
* New `backpressure.{inc,dec}` intrinsics
* New component-model-threading-related intrinsics

New features aren't yet implemented, they're left for future PRs.

* add `task_exit` option to `wasmtime-wit-bindgen` (#11665)

This builds on #11662 by optionally exposing the `TaskExit` return value from
`[Typed]Func::call_concurrent` in the bindings generated for exported functions.

Note that the first two commits are shared with #11662.

Fixes #11600

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

* make `waitable-set.{poll,wait}` and `yield` non-cancellable by default (#11671)

This fixes a divergence between the spec and the implementation.  Thanks (again)
to Luke for providing a test case, which I've added here.

This addresses half of #11582

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

* fix panic in `Instance::set_consumer` when write end is already dropped (#11669)

* fix panic in `Instance::set_consumer` when write end is already dropped

In this case, we can drop the whole stream or future immediately since there's
nothing left to do with it.

Fixes #11621

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

* add test for piping from a stream whose write end is already dropped

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

---------

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

* wasip3: Add support to `wasmtime serve` (#11646)

* wasip3: Add support to `wasmtime serve`

This commit adds support for WASIp3 to `wasmtime serve` by detecting
whether the input component is using a WASIp3 exported interface instead
of a WASIp2 exported interface (similar to how `wasmtime run` detects
which is supported).

* Fix tests

* Log guest result

* fix panic when trapping while handling multiple work items (#11678)

Now we wrap the "ready" set of work items in a struct which will gracefully
dispose of the remainder if we trap or panic while handling one of them.

Fixes #11668

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

* Implement `backpressure.{inc,dec}` (#11661)

Added to the async specification in WebAssembly/component-model#560
these are minor adaptations to the preexisting `backpressure.set`
intrinsic and are intended to replace it. The `backpressure.set`
intrinsic will remain until tooling propagates to understand
`backpressure.{inc,dec}`.

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Co-authored-by: Roman Volosatovs <rvolosatovs@users.noreply.github.com>
Co-authored-by: Joel Dice <joel.dice@fermyon.com>
bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
* p3-http: correctly handle `result` future cancellation

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

* p3-http: restructure the `content-length` test a bit

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

* test(http): keep accepting connections after errors

prtest:full

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

* test(p3-http): assert `handle` error on exceeding `content-length`

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

* p3-http: perform `content-length` check early

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

* test(p3-http): account for `handle` race condition

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

* refactor(http): reuse `get_content_length`

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

* p3-http: check `content-length` for host bodies

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

* doc(p3-http): call out that host bodies are not validated

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

* p3-http: refactor body size error send

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

* fix(p3-http): do not rely on `Drop` for host body check

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

* doc(p3-http): ensure non-default send request is documented

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

* doc(p3-http): correct `send_request` doc

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

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

wasip3: p3_http_outbound_request_content_length test is flaky

2 participants