0

I am testing a web api using the reqwest crate. I get the following error after a certain number of requests.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(8000), path: "/create_my_profile", query: None, fragment: None }, fragment: None } source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 49, kind: AddrNotAvailable, message: "Can't assign requested address" })) }

How can I handle this? I have searched github issues, etc., but could not find a solution.

Steps to reproduce:

  • os -> macos
const BASEURL: &str = "http://127.0.0.1:8000";
const NUM_USRES: usize = 500;

pub async fn login(data: &LoginUser) -> Result<Response, reqwest::Error> {
    let client = reqwest::Client::new();
    let url = format!("{}/login", BASEURL);
    client.post(&url).json(data).send().await
}

#[tokio::main]
async fn main() {
    for _ in 0..NUM_USERS {
        let login_user: LoginUser = LoginUser::random_gen();
        login(login_user).await;
    }
}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
musako
  • 897
  • 2
  • 10
  • 26
  • Have you seen https://github.com/hyperium/hyper/issues/1757 sounds it's caused by OS not closing connections fast enough. What OS are you on? – PitaJ May 12 '23 at 18:31
  • We need to see the code to know more of what might be going wrong. Perhaps you are creating too many `reqwest::Client`s? But in any case, please [edit] your question to include code (preferably complete enough to run). – Kevin Reid May 12 '23 at 22:51
  • @PitaJ I use a mac. – musako May 13 '23 at 03:40

0 Answers0