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

A time out error after upgrading from 0.11.x to 0.12.x and using http2 #2283

Open
tatodorov opened this issue May 11, 2024 · 0 comments
Open

Comments

@tatodorov
Copy link

I have the following sample code which works with reqwest 0.11.x, but I get a timeout when using reqwest 0.12.x.
When I switch to HTTP 1.1 by replacing .http2_prior_knowledge() with .http1_only(), the code works also with 0.12.x.
So, seems to be HTTP2 related.

Cargo.toml:

[package]
name = "httpclient"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.12.4", default-features = false, features = [
    "http2",
    "rustls-tls",
    "brotli",
    "gzip",
] }

# reqwest = { version = "0.11.27", default-features = false, features = [
#     "rustls-tls",
#     "brotli",
#     "gzip",
# ] }

tokio = { version = "1.32.0", features = [
    "rt-multi-thread",
    "macros",
    "fs",
    "io-util",
], default-features = false }

log = "*"
env_logger = { version = "0.11.3"}

main.rs:

use reqwest::ClientBuilder;
use reqwest::header::HeaderMap;
use std::collections::HashMap;
use std::time::Duration;
use env_logger;

#[tokio::main]
async fn main() {

    env_logger::init();

    let result = ClientBuilder::new()
        .timeout(Duration::from_secs(5))
        .pool_idle_timeout(Duration::from_secs(5))
        .tcp_keepalive(Duration::from_secs(5))
        .connect_timeout(Duration::from_secs(5))
        .connection_verbose(true)
        .https_only(true)
        .http2_prior_knowledge()
        .gzip(true)
        .brotli(true)
        .http2_adaptive_window(true)
        .build();
    

    let client = match result {
        Ok(clnt) => clnt,
        Err(error) => {
            eprintln!("Error: {:?}", error);
            return;
        }
    };

    let url = "https://search.brave.com/search?q=wifi7&offset=0";

    let headers = HeaderMap::try_from(&HashMap::from([
        ("User-Agent".to_string(), "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0".to_string()),
        ("Referer".to_string(), "https://search.brave.com/".to_string()),
    ])).unwrap();


    let result2 = client
    .get(url)
    .headers(headers)
    .send()
    .await;

    match result2 {
        Ok(resp) => println!("Response: {:#?}", resp),
        Err(err) => eprintln!("Error: {:?}", err),
    }
}

By running RUST_LOG=reqwest=trace cargo run, I see the following output:

   Compiling httpclient v0.1.0 (/workspaces/rust-playground/httpclient)
    Finished dev [unoptimized + debuginfo] target(s) in 5.60s
     Running `target/debug/httpclient`
[2024-05-11T03:44:12Z DEBUG reqwest::connect] starting new connection: https://search.brave.com/
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] a754bb40 write: b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] a754bb40 write: b"\0\0\x18\x04\0\0\0\0\0\0\x02\0\0\0\0\0\x04\0\0\xff\xff\0\x05\0\0@\0\0\x06\0\0@\0"
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] a754bb40 write: b"\0\0\x86\x01\x05\0\0\0\x01\x82\x87A\x8cAGa'^;\x07\xdc\xab\x90\xf4\xff\x04\x92a\x05\x1d\x84\x9f\xfc\xed\x07\x83Jg~\x0f,\xa8*`\x07s\x92\x9d)\xad\x17\x18a\x05\x1d\x84\x9dx\xec\x1fr\xaeC\xd2\xc7z\xbe\xd0\x7ff\xa2\x81\xb0\xda\xe0S\xfa\xd02\x1a\xa4\x9d\x13\xfd\xa9\x92\xa4\x96\x854\x0c\x8aj\xdc\xa7\xe2\x81\x02\xe1o\xedK;\xdc\x08\x9b\\\x1f\xda\x98\x8aN\xa7`@\x08\0\x10\x05L&\xb0\xb2\x9f\xcb\x01\x13k\x83S\x83\xf9c\xe7P\x87\x9b\xd9\xab\xfaR;?"
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] a754bb40 write: b"\0\0\0\x04\x01\0\0\0\0"
[2024-05-11T03:44:12Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] TODO: verbose poll_read
[2024-05-11T03:44:13Z TRACE reqwest::connect::verbose] a754bb40 write: b"\0\0\x04\x08\0\0\0\0\0\0\0\x97\xd8\0\0\x04\x03\0\0\0\0\x01\0\0\0\x07"
Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("search.brave.com")), port: None, path: "/search", query: Some("q=wifi7&offset=0"), fragment: None }, source: TimedOut }
multun added a commit to OpenRailAssociation/osrd that referenced this issue May 21, 2024
Somewhere between 0.11.27 and 0.12.3, a regression related to timeout handling was introduced.
Other users seem to have similar issues: seanmonstar/reqwest#2283
Interestingly enough, this bug report mentions http/2, but the server we're querying only supports http/1.1.
multun added a commit to OpenRailAssociation/osrd that referenced this issue May 21, 2024
Somewhere between 0.11.27 and 0.12.3, a regression related to timeout handling was introduced.
Other users seem to have similar issues: seanmonstar/reqwest#2283
Interestingly enough, this bug report mentions http/2, but the server we're querying only supports http/1.1.
multun added a commit to OpenRailAssociation/osrd that referenced this issue May 21, 2024
Somewhere between 0.11.27 and 0.12.3, a regression related to timeout handling was introduced.
Other users seem to have similar issues: seanmonstar/reqwest#2283
Interestingly enough, this bug report mentions http/2, but the server we're querying only supports http/1.1.
github-merge-queue bot pushed a commit to OpenRailAssociation/osrd that referenced this issue May 21, 2024
Somewhere between 0.11.27 and 0.12.3, a regression related to timeout handling was introduced.
Other users seem to have similar issues: seanmonstar/reqwest#2283
Interestingly enough, this bug report mentions http/2, but the server we're querying only supports http/1.1.
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

1 participant