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

fix: auto conn infinite loop if conn closed before send full bytes #36

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

chrislearn
Copy link
Contributor

We cannot assume that the client will definitely send 24 bytes.

  • If the client closes the connection before sending 24 bytes, the loop will not exit, but will be awakened infinitely, causing the current thread to fill up the core of the current CPU.
  • If the client does not disconnect but does not send the full 24 bytes, it cannot be determined whether it is http1 or http2, resulting in infinite waiting. For example:
use std::{net::{TcpStream},io::{Error, Write, Read}};
fn main()->Result<(),Error> {
    let mut conn = TcpStream::connect("127.0.0.1:5800")?;
    println!("connection ok");
    let write_content = b"GET / HTTP/1.1\r\n\r\n";
    conn.write(write_content)?;
    println!("write ok");
    let mut vec = Vec::new();
    vec.resize(1024 * 1024, b'\0');
    let read_size = conn.read(& mut vec[..])?;
    println!("{read_size}");
    println!("{}",std::str::from_utf8(&vec[..read_size]).unwrap());
    Ok(())
}

Such code will cause the client to not get the data returned by the server.

@seanmonstar seanmonstar merged commit 450cca8 into hyperium:master Sep 16, 2023
15 checks passed
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

Successfully merging this pull request may close these issues.

2 participants