Skip to content

Allow stream.{read,write}s of length 0 to query/signal readiness#444

Merged
lukewagner merged 1 commit into
mainfrom
zero-length
Apr 30, 2025
Merged

Allow stream.{read,write}s of length 0 to query/signal readiness#444
lukewagner merged 1 commit into
mainfrom
zero-length

Conversation

@lukewagner
Copy link
Copy Markdown
Member

This PR relaxes the rules for stream.{read,write} to accept lengths of 0. This can be useful for signalling and querying readiness which in turn can be used to implement non-blocking POSIX operations, as discussed in #441.

@lukewagner
Copy link
Copy Markdown
Member Author

Updated the PR based on further discussion in #441 about what happens when a 0-length read and write rendezvous. In the previous iteration, both were notified; with this update, only the writer is notified, since this ends up being what you want if there is going to be buffering (as mentioned in the PR and also this comment).

@alexcrichton
Copy link
Copy Markdown
Collaborator

cc @dicej on this as it relates to our discussion this morning. It looks like the wasip3-prototyping branch doesn't implement the spec as-is as 0-length reads/writes aren't trapped, and it also hasn't been updated to take this PR into account either. Basically I think wasip3-prototyping is an ambiguous state right now as to what 0-length reads/writes mean.

Also question for you @lukewagner. The topic of 0-length reads/writes have come up in the context of figuring out what the result of an async stream operation is. Specifically I was attempting to model the result of a stream operation as a tri-state value of either (a) completed with N items, (b) closed, or (c) cancelled. Given the way the return codes map here though is it correct to say that if you cancel a 0-length operation there's no way to figure out what happened as a result? The canonical ABI code returned will be 0, maybe eventually, and that's ambiguous whether the read/write was cancelled or "completed"?

@lukewagner
Copy link
Copy Markdown
Member Author

You're right, as currently written, after a BLOCKED cancellation, the event tuple will be the same as-if the operation completed. I wasn't sure whether this was a problem due to the fact that the cancellation comes from within the same component that receives the event, but I guess in the BLOCKED case there is a race and so this could actually lose useful information. I already think we need to slightly change the packed result of a stream operation to have a 4-bit "what happened" code separate from the 28-bit optional "payload", and so this could be fit in with that change.

dicej added a commit to bytecodealliance/wasip3-prototyping that referenced this pull request Apr 18, 2025
Updated to match WebAssembly/component-model#444

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@lukewagner
Copy link
Copy Markdown
Member Author

Sounds like this has been implemented in wasip3-prototyping/#130 so I'll merge and we can iterate as necessary in follow-up issues and PRs.

@lukewagner lukewagner merged commit 3ffb650 into main Apr 30, 2025
2 checks passed
@lukewagner lukewagner deleted the zero-length branch April 30, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants