From a2b005726419f64eb9db0478208c43ae472bb500 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 4 Aug 2021 18:49:39 +0100 Subject: [PATCH] move effective_http_timeout into InstanceConfig Signed-off-by: Ian Jackson --- README.config | 2 ++ macros/macros.rs | 2 +- src/bin/client.rs | 8 ++------ src/config.rs | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.config b/README.config index a2b9d7d..9380fed 100644 --- a/README.config +++ b/README.config @@ -110,6 +110,8 @@ Capped settings: for this long On client: give up on any http request outstanding for for this long plus http_timeout_grace + Warning messages about link problems, printed by the client, + are rate limited to no more than one per effective timeout. Client's effective timeout must be at least server's (checked). [30 s; LIMIT: 121s] diff --git a/macros/macros.rs b/macros/macros.rs index ffb1772..88828ae 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -35,7 +35,7 @@ use itertools::Itertools; /// } /// ``` #[proc_macro_derive(ResolveConfig, attributes( - limited, server, client, special + limited, server, client, computed, special ))] pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = parse_macro_input!(input as DeriveInput); diff --git a/src/bin/client.rs b/src/bin/client.rs index 7667271..83fc74f 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -27,7 +27,6 @@ trait HCC: hyper::client::connect::Connect + Clone + Send + Sync + 'static { } struct ClientContext<'c,C> { ic: &'c InstanceConfig, - effective_http_timeout: Duration, // also min err report interval, xxx doc hclient: &'c Arc>, reporter: &'c parking_lot::Mutex>, } @@ -133,7 +132,7 @@ fn submit_request<'r, 'c:'r, C:HCC>( let resp = c.hclient.request(req); let fut = Box::pin(async move { - let r = async { tokio::time::timeout( c.effective_http_timeout, async { + let r = async { tokio::time::timeout( c.ic.effective_http_timeout, async { let resp = resp.await.context("make request")?; let status = resp.status(); let resp = resp.into_body(); @@ -173,9 +172,6 @@ async fn run_client( reporter: &reporter, hclient: &hclient, ic: &ic, - effective_http_timeout: ic.http_timeout.checked_add(ic.http_timeout_grace) - .ok_or_else(|| anyhow!("calculate effective http timeout ({:?} + {:?})", - ic.http_timeout, ic.http_timeout_grace))?, }; let mut ipif = tokio::process::Command::new("sh") @@ -288,7 +284,7 @@ async fn run_client( } }, - _ = tokio::time::sleep(c.effective_http_timeout), + _ = tokio::time::sleep(c.ic.effective_http_timeout), if rx_queue_space.is_err() => { reporter.lock().filter(None, Err::( diff --git a/src/config.rs b/src/config.rs index 5a1c89f..dd78d75 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,6 +40,9 @@ pub struct InstanceConfig { #[client] pub http_retry: Duration, #[client] pub url: Uri, #[client] pub vroutes: Vec, + + // Computed, rather than looked up. Client only: + #[computed] pub effective_http_timeout: Duration, } static DEFAULT_CONFIG: &str = r#" @@ -628,6 +631,13 @@ impl<'c> ResolveContext<'c> { } } + #[throws(AE)] + pub fn computed(&self, _key: &'static str) -> T + where T: Default + { + default() + } + #[throws(AE)] pub fn special_ipif(&self, key: &'static str) -> String { match self.end { @@ -694,6 +704,14 @@ impl InstanceConfig { .parse().unwrap() } + self.effective_http_timeout = { + let a = self.http_timeout; + let b = self.http_timeout_grace; + a.checked_add(b).ok_or_else( + || anyhow!("calculate effective http timeout ({:?} + {:?})", a, b) + )? + }; + check_batch(self.max_batch_up, "max_batch_up")?; }, -- 2.30.2