Skip to content

Commit

Permalink
download_sysext: timeout after 20 seconds
Browse files Browse the repository at this point in the history
Set the default timeout to 20 seconds, so HTTP client can abort after
that timeout.
  • Loading branch information
dongsupark committed Dec 14, 2023
1 parent f624f27 commit f75d089
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protobuf = "3.2.0"
reqwest = "0.11"
sha2 = "0.10"
tempfile = "3.8.1"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread"] }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "time"] }
url = "2"
uuid = "1.2"

Expand Down
5 changes: 4 additions & 1 deletion src/bin/download_sysext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;

#[macro_use]
extern crate log;
Expand Down Expand Up @@ -322,6 +323,8 @@ impl Args {
}
}

const HTTP_CONN_TIMEOUT: u64 = 20;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
Expand All @@ -342,7 +345,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
fs::create_dir_all(&temp_dir)?;

// The default policy of reqwest Client supports max 10 attempts on HTTP redirect.
let client = Client::builder().redirect(Policy::default()).build()?;
let client = Client::builder().connect_timeout(Duration::from_secs(HTTP_CONN_TIMEOUT)).redirect(Policy::default()).build()?;

// If input_xml exists, simply read it.
// If not, try to read from payload_url.
Expand Down

0 comments on commit f75d089

Please sign in to comment.