-
Notifications
You must be signed in to change notification settings - Fork 239
wasip3: Fix fallback code when buffering writes #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexcrichton
merged 4 commits into
WebAssembly:main
from
alexcrichton:test-fs-nonblocking
Apr 22, 2026
+127
−38
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #include "test.h" | ||
| #include <dirent.h> | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <poll.h> | ||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/stat.h> | ||
| #include <unistd.h> | ||
|
|
||
| #define TEST(c) \ | ||
| do { \ | ||
| errno = 0; \ | ||
| if (!(c)) \ | ||
| t_error("%s failed (errno = %d)\n", #c, errno); \ | ||
| } while (0) | ||
|
|
||
| int main() { | ||
| int fd; | ||
| TEST((fd = open("howdy.txt", O_RDWR | O_NONBLOCK | O_CREAT, 0755)) > 0); | ||
|
|
||
| int rc, size = 0; | ||
|
|
||
| struct pollfd pollfd; | ||
| int max = 32 * 1024; | ||
| pollfd.fd = fd; | ||
|
|
||
| pollfd.events = POLLWRNORM; | ||
| for (int i = 0; size < max && i < 100; i++) { | ||
| while (size < max && (rc = write(fd, "hello", 5)) > 0) | ||
| size += rc; | ||
| TEST(poll(&pollfd, 1, -1) != -1); | ||
| } | ||
|
|
||
| TEST(size > 0); | ||
|
|
||
| struct stat stat; | ||
| TEST(fstat(fd, &stat) == 0); | ||
| TEST(stat.st_size == size); | ||
|
|
||
| TEST(lseek(fd, 0, SEEK_SET) != -1); | ||
|
|
||
| char buf[5]; | ||
| pollfd.events = POLLRDNORM; | ||
| int remaining = size; | ||
| while (remaining) { | ||
| while ((rc = read(fd, buf, sizeof(buf))) > 0) | ||
| remaining -= rc; | ||
| TEST(poll(&pollfd, 1, -1) != -1); | ||
| } | ||
|
|
||
| TEST(close(fd) != -1); | ||
| return t_status; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean
read/writecan start returningEWOULDBLOCKfor regular files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, yeah. I'm not sure how useful that is in practice, but it's the only way I could think of to test this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if an application requested O_NONBLOCK, then getting EWOULDBLOCK is exactly what it asked for. Nonetheless, I wonder how many programs are actually prepared to handle that for regular files, given ~40 years of assumptions that the flag is ignored for those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er sorry meant to think about this a bit more before landing. Do you feel that this should get backed out? I don't know how to test anything related to "ill behaving streams" otherwise since files are basically the only host-defined stream that doesn't handle zero-length reads/writes like TCP does.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Linux man page mentions:
And also:
So yeah,. there's that.. :)
I feel this leaks testing concerns into user-visible behavior so I'm leaning toward keeping the fix but backing out the nonblocking behavior for regular files. I don't have a super strong well-funded opinion for it though.
That would indeed leave some of the new code untested. As long as the test suite uses off-the-shelf, unmodified Wasm engines, we're unlikely to hit all code paths anyway. A longer-term solution might be some kind of host-side "chaos mode" that deterministically generates all kinds of odd-but-technically-correct stream behaviors. That could also be more generally useful for other languages and toolchains targeting the component model directly. I realize that is completely out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yeah ok I agree and it seems prudent. I've posted #796 to disable this, and for further testing -- in addition to a theoretical chaos mode this'd be a good use of #766 I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, this could indeed be a nice use case for component composition