Repository navigation
Conversation
Tokio only clears a socket's cached read readiness when a read returns WouldBlock. `TcpReceiveStream::poll_ready` returned that cached readiness directly, so a readiness probe (WASIp2 `pollable.ready`, a zero-length WASIp3 `stream.read`) could report ready on a fresh connection, or after a short read had drained the socket. Peek a single byte instead: `poll_peek` waits for data, end of stream or an error, and clears the readiness on WouldBlock. This costs one `recv(MSG_PEEK)` per readiness poll. Add p2 and p3 tests for fresh and drained connections.
Same class of bug as for receive streams: `try_write` only clears tokio's cached write readiness on WouldBlock, so after a short write has filled the kernel send buffer `TcpSendStream::poll_ready` still reported the socket as writable. This is visible through the zero-length WASIp3 `stream.write` readiness probe. After `poll_write_ready` reports ready, confirm with `poll(POLLOUT)` and, if the socket isn't writable, clear the readiness via `try_io` returning WouldBlock, which re-arms the waker. This costs one `poll` syscall per readiness poll. `POLLOUT` is stricter than "a write would succeed" (Linux reports not writable while the buffer is more than about half full), the same as for `poll()` itself. On non-Unix targets behaviour is unchanged. Add a WASIp3 test: the probe stays pending while the send buffer is full and completes once the peer has drained it.
This branch has not been deployed
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.
Reimplementation of #14987
Fixes #14986
Poll can report a file/socket as ready after a short try_read/write. Check again.
(This patch fixes the reported problem but the tests still look rough, so I make it draft for now)