net: document pipe try_read*/try_write* readiness behavior#8032
Merged
mattiapitossi merged 4 commits intotokio-rs:masterfrom Apr 19, 2026
Merged
net: document pipe try_read*/try_write* readiness behavior#8032mattiapitossi merged 4 commits intotokio-rs:masterfrom
mattiapitossi merged 4 commits intotokio-rs:masterfrom
Conversation
Darksonn
reviewed
Apr 10, 2026
Add a Notes section to all five try_* methods on pipe::Sender and pipe::Receiver explaining that the runtime's I/O driver only delivers readiness events after control is yielded back to it, so calling try_read/try_write before any .await returns WouldBlock even when the operation could otherwise succeed. This is the same readiness model used by every other Tokio I/O type; the pipe docs simply did not previously call it out. Refs tokio-rs#7625.
90227a3 to
adef662
Compare
Darksonn
reviewed
Apr 11, 2026
Member
|
Ah, looks like the |
Contributor
Author
|
good catch, fixed in 3c06d4b — added [ |
Member
|
Thanks! |
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.
Motivation
#7625 reports that calling
pipe::Receiver::try_readimmediately after creating the receiver returnsWouldBlockeven when data is already available in the pipe. The same applies totry_read_vectored,try_read_buf, and thetry_write*methods onpipe::Sender.This is intentional:
Registration::try_iochecks the cached readiness state and short-circuits withWouldBlockuntil the I/O driver has had a chance to deliver an event for the registration. The same model applies to every other Tokio I/O type. But thepipedocs do not currently call this out, and it's easy to assumetry_*is a thin syscall wrapper — which led to the confusion in #7625 (and to my own first attempt at "fixing" it in this PR before @Darksonn and @Thomasdezeeuw kindly explained the actual model).Solution
Add a
# Notessection to all fivetry_*methods onpipe::Senderandpipe::Receiverexplaining that the runtime's I/O driver only delivers readiness events after control has been yielded back to it, and that callingtry_*before any.await(such asreadable()/writable()) will returnWouldBlockeven when the operation could otherwise succeed.No code or behavior changes. The note follows the existing
# Notesconvention used inudp.rs,tcp/stream.rs, etc., and is positioned between# Returnand# Examplesto matchudp::UdpSocket::try_recv_fromwhich has the same shape.Verified with the docs.rs-equivalent build from the contributors guide:
No new warnings from
pipe.rs, and the rendered HTML on both theReceiverandSenderpages contains all five new# Notessections.