You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WASI streams operations are nonblocking, unless they have blocking_ in their name, so read should always return an empty list instead of blocking. The blocking_ functions are equivalent to waiting for readiness on the stream's pollable, and then calling the nonblocking variant.
This is a significant departure from POSIX, which uses the file's mode to make the read and write syscalls blocking or nonblocking. So, while it makes sense for POSIX to use an error to indicate when a nonblocking socket would block, it doesn't make sense for WASI to follow that same convention.
How can you distinguish in WASI between an EOF stream (no data will be returned in the future because the connection was closed or the end of the file is reached) and a stream where you have to wait until the stream is ready before you can read more data? The distinction is very important for std::io::copy/tokio::io::copy which needs to continue reading until EOF and only returns when EOF is reached.
When the stream is EOF, it returns Err(StreamError::Closed) as seen in the above snippet line 21. Maybe this isn't so much an "Error" as the "Err" constructor indicates, but the alternative was returning a custom enum there of Ok/Closed/Error, which we rejected on fairly arbitrary stylistic grounds.
wasmtime/crates/wasi/src/tcp.rs
Lines 719 to 723 in 6767488
Returning
0
forstd::io::ErrorKind::WouldBlock
causes downstream to interpret it as a closed stream, see:yoshuawuyts/wstd#25 (comment).
https://github.com/yoshuawuyts/wstd/blob/5ce367add5e7bcb569b6487453cb9ba94468dc99/src/io/copy.rs#L12
This is also found in:
wasmtime/crates/test-programs/src/bin/preview2_tcp_streams.rs
Lines 17 to 22 in 6767488
Given that the
wit
files already include manywould-block
errors, would it make sense to extendstream-error
to include awould-block
?The text was updated successfully, but these errors were encountered: