diff --git a/impls/src/adapters/http.rs b/impls/src/adapters/http.rs index e537cf3c4..597f9e626 100644 --- a/impls/src/adapters/http.rs +++ b/impls/src/adapters/http.rs @@ -26,6 +26,7 @@ use crate::tor::config as tor_config; use crate::tor::process as tor_process; const TOR_CONFIG_PATH: &'static str = "tor/sender"; +const SEND_TX_READ_TIMEOUT_SECONDS: u64 = 5 * 60; #[derive(Clone)] pub struct HttpSlateSender { @@ -73,7 +74,7 @@ impl HttpSlateSender { "params": [] }); - let res: String = self.post(url, None, req).map_err(|e| { + let res: String = self.post(url, None, req, None).map_err(|e| { let mut report = format!("Performing version check (is recipient listening?): {}", e); let err_string = format!("{}", e); if err_string.contains("404") { @@ -129,6 +130,7 @@ impl HttpSlateSender { url: &str, api_secret: Option, input: IN, + read_timeout: Option, ) -> Result where IN: Serialize, @@ -138,6 +140,7 @@ impl HttpSlateSender { client.use_socks = true; client.socks_proxy_addr = self.socks_proxy_addr.clone(); } + client.read_timeout = read_timeout; let req = client.create_post_request(url, api_secret, &input)?; let res = client.send_request(req)?; Ok(res) @@ -205,11 +208,13 @@ impl SlateSender for HttpSlateSender { }); trace!("Sending receive_tx request: {}", req); - let res: String = self.post(&url_str, None, req).map_err(|e| { - let report = format!("Posting transaction slate (is recipient listening?): {}", e); - error!("{}", report); - ErrorKind::ClientCallback(report) - })?; + let res: String = self + .post(&url_str, None, req, Some(SEND_TX_READ_TIMEOUT_SECONDS)) + .map_err(|e| { + let report = format!("Posting transaction slate (is recipient listening?): {}", e); + error!("{}", report); + ErrorKind::ClientCallback(report) + })?; let res: Value = serde_json::from_str(&res).unwrap(); trace!("Response: {}", res); diff --git a/impls/src/client_utils/client.rs b/impls/src/client_utils/client.rs index dd3e6410e..9da086da1 100644 --- a/impls/src/client_utils/client.rs +++ b/impls/src/client_utils/client.rs @@ -96,6 +96,8 @@ pub struct Client { pub use_socks: bool, /// Proxy url/port pub socks_proxy_addr: Option, + // Read timeout + pub read_timeout: Option, } impl Client { @@ -104,6 +106,7 @@ impl Client { Client { use_socks: false, socks_proxy_addr: None, + read_timeout: None, } } @@ -299,7 +302,8 @@ impl Client { let https = hyper_rustls::HttpsConnector::new(1); 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_read_timeout(Some(Duration::from_secs(self.read_timeout.unwrap_or(20)))); connector.set_write_timeout(Some(Duration::from_secs(20))); let client = hyper::Client::builder().build::<_, hyper::Body>(connector); Box::new( @@ -348,7 +352,8 @@ impl Client { let socks_connector = Socksv5Connector::new(addr); let mut connector = TimeoutConnector::new(socks_connector); connector.set_connect_timeout(Some(Duration::from_secs(20))); - connector.set_read_timeout(Some(Duration::from_secs(20))); + connector + .set_read_timeout(Some(Duration::from_secs(self.read_timeout.unwrap_or(20)))); connector.set_write_timeout(Some(Duration::from_secs(20))); let client = hyper::Client::builder().build::<_, hyper::Body>(connector); Box::new(