Skip to content

docs: add cancel safety section to TcpStream::peek #7305

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cvengler
Copy link

@cvengler cvengler commented May 4, 2025

Fix #7303

@cvengler
Copy link
Author

cvengler commented May 4, 2025

cc @maminrayej

Comment on lines 1073 to 1079
/// # Cancel safety
///
/// This method is cancel safe, as no underlying state gets modified.
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stay consistent with the wording that is used throughout the code base for documenting cancel safety:

This method is cancel safe. If the method is used as the event in a tokio::select! statement and some other branch completes first, then it is guaranteed that <insert the appropriate text here>.

For example for TcpListener::accept, it's:

This method is cancel safe. If the method is used as the event in a tokio::select! statement and some other branch completes first, then it is guaranteed that no new connections were accepted by this method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link to tokio::select! isn't working. You need to mark the link properly. See the other examples of how to say where the link should go.

@Darksonn Darksonn added T-docs Topic: documentation A-tokio Area: The main tokio crate M-net Module: tokio/net labels May 5, 2025
@cvengler cvengler force-pushed the cancel-safe-peek branch from 7e1f56f to 02f6d2f Compare May 6, 2025 17:49
@cvengler
Copy link
Author

cvengler commented May 6, 2025

updated to reflect the suggestion.

Comment on lines +1075 to +1078
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no data was permanently read from the
/// stream's buffer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Unlike read, peek never reads data permanently even if you let it complete.

Suggested change
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no data was permanently read from the
/// stream's buffer.
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no peek was performed, and that `buf`
/// has not been modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-net Module: tokio/net T-docs Topic: documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lack of documentation regarding cancel safety on TcpStream::peek
3 participants