actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.38k stars 1.66k forks source link

awc: "IO error: bytes remaining on stream" on some websites #2106

Open Shnatsel opened 3 years ago

Shnatsel commented 3 years ago

Expected Behavior

awc being able to successfully download the websites that work with curl and Firefox.

Current Behavior

On some websites, e.g. http://mapleleafs.com, awc fails with the following error:

IO error: bytes remaining on stream

42 out of the top million websites are affected. List of all affected websites: awc-bytes-remaining-on-stream.txt.gz

Steps to Reproduce (for bugs)

  1. git clone https://github.com/Shnatsel/rust-http-clients-smoke-test
  2. cd rust-http-clients-smoke-test/awc
  3. cargo build --release
  4. target/release/awc-smoke-test

Context

I am testing a bunch of HTTP clients on the top million websites according to the Feb 3 Tranco list.

Your Environment

Linux, Ubuntu 20.04 LTS

fakeshadow commented 3 years ago

The site mentioned in issue does not return a proper response head.

Below is a response head from one of the 42 sites and it can not be parsed and would always end up with partial response until eof happen which result in the error mentioned in issue.

fn main() {
    let src = b"HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.huntsvilleal.gov/\r\n";
    let mut headers: [httparse::Header<'_>; 1] = [httparse::EMPTY_HEADER; 1];
    let mut res = httparse::Response::new(&mut headers);
    assert_eq!(res.parse(src), Ok(httparse::Status::Partial));
}

It would be possible to take a guess and fix the response with an additional \r\n. But is it the right thing to do?

rustdesk commented 3 years ago

I got similar issue on my server https://github.com/rustdesk/rustdesk, not sure if be related to https://github.com/tokio-rs/tokio/issues/2331