wasip3: Finish nonblocking I/O implementation for TCP#782
Merged
alexcrichton merged 6 commits intoWebAssembly:mainfrom Apr 13, 2026
Merged
wasip3: Finish nonblocking I/O implementation for TCP#782alexcrichton merged 6 commits intoWebAssembly:mainfrom
alexcrichton merged 6 commits intoWebAssembly:mainfrom
Conversation
This commit fills out the final bits of nonblocking I/O for TCP sockets. This necessitates an implementation of nonblocking I/O for `stream<u8>` on both the reading and the writing side of things. Additionally things like TCP accepts now work, too. All tests are now passing on the WASIp3 target and the `FAILP3` directive is now removed since it's no longer necessary. The internals of the implementation here are pretty gnarly. This is due to the need to bridge the readiness-based-model of `poll` with the completion-based model of the component model. This implementation contains optimizations for 0-length reads/writes to use those to signal readiness if the host supports that, but this falls back to internally-buffered reads/writes if that is not supported. This should resolve all remaining TODOs for WASIp3 that I know of at least in wasi-libc, so after this it'd be switching to bug-finding mode and handling bug reports as projects are compiled with wasip3.
Collaborator
Author
|
cc @badeend, would you be willing to take a look at this? I realize that you may not be the most familiar with this code so it's totally fine if you'd rather not, too. |
dicej
approved these changes
Apr 9, 2026
dicej
reviewed
Apr 9, 2026
Co-authored-by: Joel Dice <joel.dice@akamai.com>
Collaborator
Author
|
I'm going to go ahead and merge this @badeend but I'd still value your input if you get a chance in the future to take a look, happy to have follow-ups! |
badeend
reviewed
Apr 20, 2026
Member
badeend
left a comment
There was a problem hiding this comment.
@alexcrichton I reviewed this change and found a few potential issues. Note that I'v only read the code and haven’t confirmed every suspicion. It could very well be that things are already handled properly, but just some place else that Ive missed.
This was referenced Apr 21, 2026
alexcrichton
added a commit
that referenced
this pull request
Apr 21, 2026
Pointed out in review of #782
alexcrichton
added a commit
that referenced
this pull request
Apr 22, 2026
This commit fixes mistakes from #782 where the fallback code for buffering writes wasn't handled properly. Specifically when a completion event came in through `poll` it didn't fully update the internal state of the stream, such as kicking off further writes or cleaning up the internal buffer. This is fixed by refactoring the logic already present during a normal `write` to get executed in this event. Testing this is unfortunately not trivial. There aren't really all that many streams we have access to natively in Wasmtime, and TCP is "well behaved" and doesn't execute any of these fallbacks anyway. The closest way to test this is filesystem-based streams, but Wasmtime's default behavior is to lie and just do blocking operations on these streams regardless. Through changes in Wasmtime, and flags to Wasmtime, however, it's possible to Wasmtime in a mode where filesystem streams are "ill behaved" where zero-length reads don't signal readiness, triggering these fallback paths. With those changes the added test here, and minor additionally support for nonblocking reads/writes, exercise these paths and triggers the previous bug.
Collaborator
Author
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 commit fills out the final bits of nonblocking I/O for TCP sockets. This necessitates an implementation of nonblocking I/O for
stream<u8>on both the reading and the writing side of things. Additionally things like TCP accepts now work, too. All tests are now passing on the WASIp3 target and theFAILP3directive is now removed since it's no longer necessary.The internals of the implementation here are pretty gnarly. This is due to the need to bridge the readiness-based-model of
pollwith the completion-based model of the component model. This implementation contains optimizations for 0-length reads/writes to use those to signal readiness if the host supports that, but this falls back to internally-buffered reads/writes if that is not supported.This should resolve all remaining TODOs for WASIp3 that I know of at least in wasi-libc, so after this it'd be switching to bug-finding mode and handling bug reports as projects are compiled with wasip3.