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

Infinite loop on Stream::poll_shutdown() #92

Open
hatoo opened this issue Nov 29, 2024 · 3 comments
Open

Infinite loop on Stream::poll_shutdown() #92

hatoo opened this issue Nov 29, 2024 · 3 comments

Comments

@hatoo
Copy link

hatoo commented Nov 29, 2024

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
while self.session.wants_write() {
ready!(self.write_io(cx))?;
}

self.write_io(cx) in the snippet may returns Ok(0) and causing an infinite loop.

I've faced this issue in my project.
I've failed to minimize codes that trigger this issue but please let me know if you want to see codes.

@quininer
Copy link
Member

quininer commented Nov 29, 2024

The write_io returns Ok(0) There are two possibilities:

  1. There is no data to be written in session. this is not possible because we have checked .wants_write().
  2. The underlying IO stream returns 0 instead of pending. this means that you are using a bad IO stream implement.

@hatoo
Copy link
Author

hatoo commented Dec 2, 2024

Hi, I've found that H2Upgraded::poll_write in hyper returns Ok(0) on the situation and I made an issue to hyper hyperium/hyper#3801

@seanmonstar said

Returning Ok(0) is the normal way for IO resources to indicate no more bytes are allowed (see https://doc.rust-lang.org/std/io/trait.Write.html#tymethod.write).

I think he said the right thing about Ok(0) according to https://doc.rust-lang.org/std/io/trait.Write.html#tymethod.write.
and tokio-rustls should be aware of Ok(0) as a writing result.

@ctz
Copy link
Member

ctz commented Dec 2, 2024

Sounds like we should convert a Ok(0) from write to ErrorKind::WriteZero and have it fail the whole connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants