From 938d1f6e7735b46ade1b1b2506d3f2e38fd62f1e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 22 Apr 2024 10:55:48 -0700 Subject: [PATCH] add conf item for sender retry backoff limit Signed-off-by: Jason Volk --- conduwuit-example.toml | 5 +++++ src/config/mod.rs | 9 +++++++++ src/service/sending/mod.rs | 7 ++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 71d7b261..669a5da4 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -580,6 +580,11 @@ allow_profile_lookup_federation_requests = true # Defaults to 180 seconds #sender_idle_timeout = 180 +# Federation sender transaction retry backoff limit +# +# Defaults to 86400 seconds +#sender_retry_backoff_limit = 86400 + # Appservice URL request connection timeout # # Defaults to 120 seconds diff --git a/src/config/mod.rs b/src/config/mod.rs index 402f0439..d1034d96 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -88,6 +88,7 @@ pub struct Config { #[serde(default = "default_cleanup_second_interval")] pub cleanup_second_interval: u32, + #[serde(default = "default_dns_cache_entries")] pub dns_cache_entries: u32, #[serde(default = "default_dns_min_ttl")] @@ -102,12 +103,14 @@ pub struct Config { pub dns_tcp_fallback: bool, #[serde(default = "true_fn")] pub query_all_nameservers: bool, + #[serde(default = "default_max_request_size")] pub max_request_size: u32, #[serde(default = "default_max_concurrent_requests")] pub max_concurrent_requests: u16, #[serde(default = "default_max_fetch_prev_events")] pub max_fetch_prev_events: u16, + #[serde(default = "default_request_conn_timeout")] pub request_conn_timeout: u64, #[serde(default = "default_request_timeout")] @@ -132,12 +135,15 @@ pub struct Config { pub sender_timeout: u64, #[serde(default = "default_sender_idle_timeout")] pub sender_idle_timeout: u64, + #[serde(default = "default_sender_retry_backoff_limit")] + pub sender_retry_backoff_limit: u64, #[serde(default = "default_appservice_timeout")] pub appservice_timeout: u64, #[serde(default = "default_appservice_idle_timeout")] pub appservice_idle_timeout: u64, #[serde(default = "default_pusher_idle_timeout")] pub pusher_idle_timeout: u64, + #[serde(default)] pub allow_registration: bool, #[serde(default)] @@ -502,6 +508,7 @@ impl fmt::Display for Config { ("Query all nameservers", &self.query_all_nameservers.to_string()), ("Maximum request size (bytes)", &self.max_request_size.to_string()), ("Maximum concurrent requests", &self.max_concurrent_requests.to_string()), + ("Sender retry backoff limit", &self.sender_retry_backoff_limit.to_string()), ("Request connect timeout", &self.request_conn_timeout.to_string()), ("Request timeout", &self.request_timeout.to_string()), ("Request total timeout", &self.request_total_timeout.to_string()), @@ -892,6 +899,8 @@ fn default_sender_timeout() -> u64 { 180 } fn default_sender_idle_timeout() -> u64 { 180 } +fn default_sender_retry_backoff_limit() -> u64 { 86400 } + fn default_appservice_timeout() -> u64 { 120 } fn default_appservice_idle_timeout() -> u64 { 300 } diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index a9ddeb0e..43f3959d 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -409,9 +409,10 @@ impl Service { .and_modify(|e| match e { TransactionStatus::Failed(tries, time) => { // Fail if a request has failed recently (exponential backoff) - const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); - let mut min_elapsed_duration = Duration::from_secs(self.timeout) * (*tries) * (*tries); - min_elapsed_duration = cmp::min(min_elapsed_duration, MAX_DURATION); + let min_duration = Duration::from_secs(services().globals.config.sender_retry_backoff_limit); + let max_duration = Duration::from_secs(services().globals.config.sender_timeout); + let min_elapsed_duration = min_duration * (*tries) * (*tries); + let min_elapsed_duration = cmp::min(min_elapsed_duration, max_duration); if time.elapsed() < min_elapsed_duration { allow = false; } else {