From f75d089562e4a2a92f90b51507e70f62552b8eeb Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Thu, 14 Dec 2023 17:43:21 +0100 Subject: [PATCH] download_sysext: timeout after 20 seconds Set the default timeout to 20 seconds, so HTTP client can abort after that timeout. --- Cargo.toml | 2 +- src/bin/download_sysext.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8375a8a..c678464 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/bin/download_sysext.rs b/src/bin/download_sysext.rs index 5eadb8b..5a40a0e 100644 --- a/src/bin/download_sysext.rs +++ b/src/bin/download_sysext.rs @@ -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; @@ -322,6 +323,8 @@ impl Args { } } +const HTTP_CONN_TIMEOUT: u64 = 20; + #[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); @@ -342,7 +345,7 @@ async fn main() -> Result<(), Box> { 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.