Getting Error: Connect(Timeout) with actix_web client

i am trying to create a web client using actix_web, but getting Error: Connect(Timeout) error. is there a way to increase timeout settings ?

use actix_rt::System;
use actix_web::client::Client;
use futures::future::Future;
use futures::lazy;
use actix_http::Error;

fn main() -> Result<(), Error> {
System::new("test").block_on(lazy(|| {
let mut client = Client::default();
client.get("https://example.org") // <- Create request builder
.send() // <- Send http request
.from_err()
.and_then(|mut response| { // <- server http response
println!("Response: {:?}", response);
response
.body()
.from_err()
.map(|body| println!("Downloaded: {:?} bytes", body))
})
}))
}

Please use code fences to formst your code like this,

```rust
// your code here
```

thanks i added the fences to the code.

This StackOverflow post seems relavant

https://stackoverflow.com/questions/54609316/how-do-i-prevent-a-timeout-problem-while-streaming-large-files-with-an-actix-web

Tldr; use streaming instead of body

well the problem is timeout in sending the request, I think streaming will only work once I got the response and the response will come once request is send.

the request is getting timeout in first place as the server which I am trying to connect takes 4-5 sec to respond with result.

correct me if I am wrong.

You set the timeout with ClientBuilder::timeout and then finalize the builder to get a Client with the configured timeout.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.