Http client (reqwest) closed connection when server shutdown (warp)

Hello,

I use warp as a server:

let r2 = warp::path("r2");
let route_2 = r2
        .and(warp::post())
        .and(warp::body::json())
        .and(with_db(db_pool.clone()))
        .and_then(handlers::post_handler); // post cmd_result to the database```

let routes = test_route
        .or(route_1)
        .or(route_2)
        .with(warp::cors().allow_any_origin())
        .recover(error::handle_rejection);

warp::serve(routes).run(server).await;

And i use a client with reqwest. Let's say:

loop{
        let client = reqwest::Client::new();

        let res = client.post("http:// .... /r1")
                        .body("body 1")
                        .send()
                        .await?;
=====> sleep 5 min for example
        let res = client.post("http:// .... /r2")
                        .body("body 2")
                        .send()
                        .await?;
}

If a shutdown the warp server during this 5 min sleep, the reqwest client shutdown too. I would like to prevent that, and that the client still continues to submit request to the server.

Any idea?

Thanks

If your server is down I`d guess your call to client.post will return some kind of error. Are you treating this error? Maybe that will cause panic! ?

P.S. I am guessing this without any prior knowledge of reqwest

Well i think it works but it wasn't. I was too fast.

The error is:

Error: reqwest::Error { kind: Request, url: "http://192.168.0.40:8080/", source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })) }

I handle the erreur like:

let r: bool = match res.status() {
            StatusCode::OK => {
                //println!("ok");
                true
            }
            _ => {
                println!("HTTP server is not responding ...");
                false
            }
        };

But the code never goes into the false* case

I don't handle the error the right way.

This is how to do:

let res = client.post(&url)
                        .body("body")
                        .send()
                        .await;

match res {
       Err(e) => {println!("server not responding");},
       Ok(_) => {}, 
}