Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout Client requests after 20 seconds #3054

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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