posborne opened PR #13345 from posborne:wasi-http-cli-exit-0-not-error to bytecodealliance:main:
When a guest calls
wasi:cli/exit(ok)from within awasi:http/handlerinstance, the host exit implementation returns Err(I32Exit(0)). This propagated as a worker error, causing wasmtime serve to log a spurious "worker error" message and wasm backtrace on what is actually a clean, guest-controlled shutdown.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
posborne requested pchickey for a review on PR #13345.
posborne requested wasmtime-wasi-reviewers for a review on PR #13345.
alexcrichton commented on PR #13345:
Thanks! Could a test be added for this as well? For example
crates/test-programs/src/bin/p3_cli_serve_hello_world.rsand related similar programs are how we're currently testingwasmtime serve
posborne commented on PR #13345:
Thanks! Could a test be added for this as well? For example crates/test-programs/src/bin/p3_cli_serve_hello_world.rs and related similar programs are how we're currently testing wasmtime serve
Yeah, I'll add a test for this general case (one request per session) -- the change here just removes error logging in the non-error case but coverage would be useful even if it isn't asserting on log non-existence.
posborne requested wasmtime-core-reviewers for a review on PR #13345.
posborne updated PR #13345.
posborne commented on PR #13345:
@alexcrichton In doing these tests, I think I found a related bug that breaks use of the future returned by
response.newintended to indicate when trasmission of the response is complete.Currently, in wasmtime, it is possible for this to indicate completion before the bytes have been handed off to hyper. If the guest keys off this to exit, then bytes are dropped on the floor. Here I have pushed 3 additional commits:
- A basic test showing/covering how to use wasi-http with single-request-per-instance via backpressure and
cli:exit. This test only fails spuriously due to the race on the response actually being handed off prior to repsonse future resolution.- A test case that consistently reproduces the spurious failure from 1.
- A patch to the serve implementation that changes the behavior to make these tests pass.
The final patch in the series (dfe334964444c41dd194c9d7703526e4c1a2bcbf) I'm not entirely particularly confident in as I don't feel I have a confident grasp on the various futures going on and where/how errors in this chain might be involved.
@tschneidereit It sounds like you've also been doing some work with
cli:exitandwasi-http-- do the test cases here make sense and have you seen similar results? Is the approach taken in my tests a valid use of the future provided byresponse.new?
Last updated: Jun 01 2026 at 09:49 UTC