-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
wasi: Handle read(0) with file streams #8611
wasi: Handle read(0) with file streams #8611
Conversation
b31e9a6
to
a8bd804
Compare
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'm a little hesitant to provide such a strong guarantee that a read of size 0 is effectively a stat
on all files. Would it work to instead pass the read size to read_result
and don't return Closed
if the read size is zero?
I don't think that works, as wasmtime/crates/wasi/wit/deps/io/streams.wit Lines 51 to 53 in 7a91375
|
I think it still satisfies the contract though because the streams interface is supposed to be super general and it's always possible for a generic stream to get disconnected at any time. For example if you do a zero-length read on a socket it may say it's ready only for the next read to say it's closed. |
Fair enough. I've pushed a change to that effect. |
* Test that wasi file streams can handle read(0) * Zero-sized reads don't fail for file streams * Accidentally removed the `read(0)` when refactoring the test
* wasi: Handle read(0) with file streams (#8611) * Test that wasi file streams can handle read(0) * Zero-sized reads don't fail for file streams * Accidentally removed the `read(0)` when refactoring the test * Update release notes
The
read
method on streams should support a size argument of zero, to test if the stream is still open. However, the implementation ofread
for open files was unconditionally treating a read that would return zero bytes as an indication that the stream was closed.This PR fixes this bug by handling a
read(0)
as an explicit test to see if the current position is at the end of the file.