http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

Recent update made reusing h1 Client result in unexpected error #296

Closed Jonathas-Conceicao closed 3 years ago

Jonathas-Conceicao commented 3 years ago

After updating surf's inner dependency, http-client, to it's latest v6.3 release reusing surf's client has been giving me a unexpected error.

I have the following reproducible example using some samples from my original project:

main.rs:

#[async_std::main]
async fn main() {
    let _mock_guard = mockito::mock("GET", "/report")
        .with_status(200)
        .expect_at_least(2)
        .create();

    let client = surf::Client::default();
    let url = &format!("{}/report", mockito::server_url());
    client.get(url).send().await.unwrap();
    client.get(url).send().await.unwrap();
}

Cargo.toml:

[package]
name = "test-surf"
version = "0.1.0"
authors = ["Jonathas-Conceicao <jonathas.conceicao@ossystems.com.br>"]
edition = "2018"

[dependencies]
async-std = { version = "1", features = ["attributes"] }
surf = { version = "2", default-features = false, features = ["h1-client"] }
http-client = "=6.3"
mockito = "0.29"

The second get from client gives an connection closed error.

How ever if I instead pin http-client = "=6.2" both requests successfully complete as expected. Re-creating the surf::Client for the second request fixes the issue on v6.3 but is far from ideal.

I'm reporting this issue here since surf is what I have actually been using in my project, but maybe it should be moved to the http-client project.

Fishrock123 commented 3 years ago

This is the same issue as https://github.com/http-rs/http-client/issues/75

Fishrock123 commented 3 years ago

Among other problems, I am beginning to suspect that mockito pretends it accepts HTTP/1.1 but makes no attempt at actually maintaining keep-alive behavior.

Fishrock123 commented 3 years ago

@Jonathas-Conceicao Could you please try running cargo-update or otherwise updating to http-client 6.3.4 and let me know if it works for you?

Jonathas-Conceicao commented 3 years ago

It is fixed with the http-client v6.3.4, thanks for the quick response.