chiark / gitweb /
move effective_http_timeout into InstanceConfig
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Aug 2021 17:49:39 +0000 (18:49 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Aug 2021 17:49:39 +0000 (18:49 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.config
macros/macros.rs
src/bin/client.rs
src/config.rs

index a2b9d7d31d70b79c77b116c3c9b27cf2aa771db9..9380fed4e2339db302185b2bb441a0d072be926d 100644 (file)
@@ -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]
 
index ffb1772baf81ba2478a20a26e34e64dc03d93bc2..88828ae82a0f4a2b01f3f2aad8c0667a1dcfce69 100644 (file)
@@ -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);
index 7667271feeaff2b6a241c232df0ed30f8539e4f0..83fc74f0d332909352f11a615b90d8258200e926 100644 (file)
@@ -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<hyper::Client<C>>,
   reporter: &'c parking_lot::Mutex<Reporter<'c>>,
 }
@@ -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<C:HCC>(
     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<C:HCC>(
           }
         },
 
-        _ = 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::<Void,_>(
index 5a1c89f6a581202842d965cfcfb2ab54f4d9d844..dd78d75733dbdcfddebf33978e63cc39f7ab219c 100644 (file)
@@ -40,6 +40,9 @@ pub struct InstanceConfig {
   #[client]  pub http_retry:                   Duration,
   #[client]  pub url:                          Uri,
   #[client]  pub vroutes:                      Vec<IpNet>,
+
+  // 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<T>(&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")?;
       },