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

Increases network read timeout to 5 minutes when sending a payment via HTTP #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions impls/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -129,6 +130,7 @@ impl HttpSlateSender {
url: &str,
api_secret: Option<String>,
input: IN,
read_timeout: Option<u64>,
) -> Result<String, ClientError>
where
IN: Serialize,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions impls/src/client_utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub struct Client {
pub use_socks: bool,
/// Proxy url/port
pub socks_proxy_addr: Option<SocketAddr>,
// Read timeout
pub read_timeout: Option<u64>,
}

impl Client {
Expand All @@ -104,6 +106,7 @@ impl Client {
Client {
use_socks: false,
socks_proxy_addr: None,
read_timeout: None,
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down