Skip to content
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

add debug_assert in case pos > cap for copy_bidirectional #4125

Merged
merged 1 commit into from Sep 22, 2021

Conversation

suikammd
Copy link
Contributor

Motivation

Wrong poll_write implementation may lead to thread blocking.
e.g., poll_write returns written length larger than cap. When reader connection alive, thread will stuck in buf_copy.

Solution

This is hard to debug, maybe add a debug_assert! will help.

// If pos larger than cap, this loop will never stop.
// In particular, user's wrong poll_write implementation returning
// incorrect written length may lead to thread blocking.
debug_assert!(self.pos <= self.cap, "pos should never larger than cap");
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we should give the user an better error message.

Suggested change
debug_assert!(self.pos <= self.cap, "pos should never larger than cap");
debug_assert!(self.pos <= self.cap, "writer returned length larger than input slice");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Sep 22, 2021
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-io Module: tokio/io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants