fix a couple of partial read/write bugs#11981
Merged
dicej merged 3 commits intobytecodealliance:mainfrom Nov 4, 2025
Merged
Conversation
If one end of a stream does a partial read or write, we leave the other end in a `GuestReady` state, allowing further reads or writes to proceed until the buffer has been drained or filled, respectively. However, once we've delivered the event regarding the partial operation, we need to set the state back to `Open`, since we'll have released the buffer back to the guest at that point. Signed-off-by: Joel Dice <[email protected]>
If the `StreamProducer` calls `Destination::set_buffer`, we need to make sure all the items in that buffer have been delivered to the receiver (or the receiver closes its end) before telling it the write end has been dropped. Signed-off-by: Joel Dice <[email protected]>
These cover a couple of scenarios where the guest and/or host read owned resource items one-at-a-time from writes of more than one item, forcing the writer to re-take ownership of the unwritten items between writes. This also covers the case where the host's `StreamProducer` returns `StreamResult::Dropped` after calling `Destination::set_buffer`, in which case Wasmtime must delay telling the other end about the dropped stream until that buffer has been drained. Signed-off-by: Joel Dice <[email protected]>
alexcrichton
approved these changes
Nov 4, 2025
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.
This fixes and adds test coverage for a couple of bugs involving component model streams:
delay returning
Droppeduntil producer buffer drainedIf the
StreamProducercallsDestination::set_buffer, we need to make sure all the items in that buffer have been delivered to the receiver (or the receiver closes its end) before telling it the write end has been dropped.reset read/write state back to
Openon event deliveryIf one end of a stream does a partial read or write, we leave the other end in a
GuestReadystate, allowing further reads or writes to proceed until the buffer has been drained or filled, respectively. However, once we've delivered the event regarding the partial operation, we need to set the state back toOpen, since we'll have released the buffer back to the guest at that point.