Skip to content

Commit

Permalink
Timeout after 20 seconds (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlesceller authored and antiochp committed Sep 24, 2019
1 parent 973a03c commit 8417221
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tokio-tcp = "0.1"
tokio-rustls = "0.7"
http = "0.1.5"
hyper-rustls = "0.14"
hyper-timeout = "0.2"
futures = "0.1.21"
rustls = "0.13"
url = "1.7.0"
Expand Down
8 changes: 7 additions & 1 deletion api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use hyper::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, USER_AGENT};
use hyper::rt::{Future, Stream};
use hyper::{Body, Client, Request};
use hyper_rustls;
use hyper_timeout::TimeoutConnector;
use serde::{Deserialize, Serialize};
use serde_json;
use std::time::Duration;
use tokio::runtime::Runtime;

pub type ClientResponseFuture<T> = Box<dyn Future<Item = T, Error = Error> + Send>;
Expand Down Expand Up @@ -195,7 +197,11 @@ where

fn send_request_async(req: Request<Body>) -> Box<dyn Future<Item = String, Error = Error> + Send> {
let https = hyper_rustls::HttpsConnector::new(1);
let client = Client::builder().build::<_, Body>(https);
let mut connector = TimeoutConnector::new(https);
connector.set_connect_timeout(Some(Duration::from_secs(20)));
connector.set_read_timeout(Some(Duration::from_secs(20)));
connector.set_write_timeout(Some(Duration::from_secs(20)));
let client = Client::builder().build::<_, hyper::Body>(connector);
Box::new(
client
.request(req)
Expand Down

0 comments on commit 8417221

Please sign in to comment.