diff options
author | Christoph Prokop <christoph.prokop@atos.net> | 2021-04-13 10:49:54 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-04-13 11:28:58 +0200 |
commit | 441ae36017058ecbf66951c26176f24fb809471d (patch) | |
tree | 4d606c6f4ccc4c85fd451c91f132da0ee7cfd224 /src | |
parent | b1d9a89c93eb500bfd14f236830b8bdc73f2ee74 (diff) |
Add configurable timeout
This patch adds a configurable timeout value (default 10 seconds)
in the Endpoint struct.
This way we get an error if the connection to the endpoint is stalled.
Signed-off-by: Christoph Prokop <christoph.prokop@atos.net>
Pair-programmed-with: Matthias Beyer <matthias.beyer@atos.net>
Suggested-by: Matthias Beyer <matthias.beyer@atos.net>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/config/endpoint_config.rs | 4 | ||||
-rw-r--r-- | src/endpoint/configured.rs | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/config/endpoint_config.rs b/src/config/endpoint_config.rs index 69405dc..05d420f 100644 --- a/src/config/endpoint_config.rs +++ b/src/config/endpoint_config.rs @@ -50,6 +50,10 @@ pub struct Endpoint { #[getset(get = "pub")] network_mode: Option<String>, + + /// Duration length of timeout for connecting endpoint + #[getset(get = "pub")] + timeout: Option<u64>, } /// The type of an endpoint diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index f850ff6..8fdec64 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -84,8 +84,13 @@ impl Endpoint { Endpoint::check_api_version_compat(epc.required_docker_api_versions().as_ref(), &ep); let imgs_avail = Endpoint::check_images_available(epc.required_images().as_ref(), &ep); - let (versions_compat, api_versions_compat, imgs_avail) = - tokio::join!(versions_compat, api_versions_compat, imgs_avail); + let (versions_compat, api_versions_compat, imgs_avail) = { + let timeout = std::time::Duration::from_secs(epc.endpoint().timeout().unwrap_or(10)); + let versions_compat = tokio::time::timeout(timeout, versions_compat); + let api_versions_compat = tokio::time::timeout(timeout, api_versions_compat); + let imgs_avail = tokio::time::timeout(timeout, imgs_avail); + tokio::join!(versions_compat, api_versions_compat, imgs_avail) + }; let _ = versions_compat.with_context(|| { anyhow!( |