add conf item for sender retry backoff limit

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-04-22 10:55:48 -07:00 committed by June
parent f273e8feb5
commit 938d1f6e77
3 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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 }

View file

@ -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 {