dicej requested alexcrichton for a review on PR #11763.
dicej opened PR #11763 from dicej:fix-11703 to bytecodealliance:main:
This addresses #11703 by allowing the embedder to "short-circuit" host-to-host streams and keep them flowing after the guest instance and its store have been disposed. Besides fixing that bug, it makes common proxy and full-duplex streaming scenarios more efficient by getting the Wasmtime runtime out of the way as early as possible, avoiding the extra memory and indirection overhead which would otherwise be imposed.
See the individual commit messages for details. Here's a summary:
- Add
StreamReader::try_intofor coercing a host-created stream into theStreamProducerimplementation (or possibly a subset of it) that was used to create it.wasmtime-wasi-httpnow uses this to unmask guest bodies which are really host bodies.- Use
tokio::task::spawninstead ofAccessor::spawnto handle connection I/O for outgoingwasmtime-wasi-httprequests. This ensures that the connection remains alive after the store is disposed.Note that the implementation of
StreamReader::try_intorequired adding a default-implementedStreamProducer::try_intofunction for doing the coercion. The signature of that function is a bit awkward given that we have to erase the types and do runtime downcasts internally. The upside is that it supports the scenario where theStreamProducerimplementation is!Unpin(meaning it cannot be downcasted, AFAICT), in which case it may be coerced into a type representing a relevant subset which isUnpin.<!--
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
-->
dicej requested wasmtime-wasi-reviewers for a review on PR #11763.
dicej requested wasmtime-core-reviewers for a review on PR #11763.
dicej requested wasmtime-default-reviewers for a review on PR #11763.
@rvolosatovs you might have opinions about https://github.com/bytecodealliance/wasmtime/pull/11763/commits/30afd9fa9e2a7adbf768c476a6119851e229ff5b
alexcrichton submitted PR review.
alexcrichton created PR review comment:
This
Box::new(*...)shouldn't be necessary I think? In theoryPin::into_inner(me)should suffice here I believe
alexcrichton created PR review comment:
Could this happen during the construction of
Responseinstead of here? Then I believe this would naturally fall through toBody::Hostbelow?
dicej submitted PR review.
dicej created PR review comment:
The compiler doesn't like that:
error[E0277]: `dyn std::any::Any` cannot be unpinned --> crates/wasi-http/src/p3/body.rs:543:32 | 543 | Ok(Pin::into_inner(me)) | --------------- ^^ the trait `std::marker::Unpin` is not implemented for `dyn std::any::Any` | | | required by a bound introduced by this call
alexcrichton created PR review comment:
Weird!
let me = Pin::into_inner(me); Ok(me)works though.I think it's because it's trying to coerce
me: Pin<Box<Self>>intoPin<Box<dyn Any>>and then go throughPin::into_innerto get out theBox<dyn Any>which doesn't work becausedyn Anyindeed does not implementUnpin. By separating it out it guides inference correctly.
alexcrichton submitted PR review.
dicej updated PR #11763.
dicej submitted PR review.
dicej created PR review comment:
Good idea; done!
dicej has enabled auto merge for PR #11763.
dicej merged PR #11763.
Last updated: Dec 06 2025 at 07:03 UTC