-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
wasmtime-wasi: Unexpected tcp stream break (Returning 0 for std::io::ErrorKind::WouldBlock
)
#9667
Comments
WASI streams operations are nonblocking, unless they have 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 |
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. |
Thanks for your kind explanation! wasmtime/crates/wasi/wit/deps/io/streams.wit Lines 47 to 54 in 6767488
I think it would be helpful to update the doc to explicitly note this situation for users. |
For the same reason, there's a potential bug in wasmtime/crates/wasi/src/stream.rs Lines 23 to 28 in 6767488
The wasmtime/crates/wasi/src/tcp.rs Lines 757 to 762 in 6767488
wasmtime/crates/wasi/src/tcp.rs Lines 739 to 745 in 6767488
However, |
Maybe all we really need is to ensure that every |
would-block
in stream-error
(Returning 0 from TcpReader::read)std::io::ErrorKind::WouldBlock
)
Thanks, it sounds like this is indeed a bug in wasmtime-wasi then. Can you create a minimal reproduction so I can work on a fix and use it as a test once we have the fix in? Something along the lines of https://github.com/bytecodealliance/wasmtime/blob/main/crates/test-programs/src/bin/preview2_tcp_streams.rs |
std::io::ErrorKind::WouldBlock
)std::io::ErrorKind::WouldBlock
)
Thanks! Its a holiday weekend here so I’ll get to this next week. |
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 thewit
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: