diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 933dbeb6..71d7b261 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -512,23 +512,24 @@ allow_profile_lookup_federation_requests = true ## ## Generally these defaults are the best, but if you find a reason to need to change these they are here. -# Default/base connection timeout +# Default/base connection timeout. # This is used only by URL previews and update/news endpoint checks # # Defaults to 10 seconds #request_conn_timeout = 10 -# Default/base request timeout -# This is used only by URL previews and update/news endpoint checks +# Default/base request timeout. The time waiting to receive more data from another server. +# This is used only by URL previews, update/news, and misc endpoint checks # # Defaults to 35 seconds #request_timeout = 35 -# Default/base max idle connections per host +# Default/base request total timeout. The time limit for a whole request. This is set very high to not +# cancel healthy requests while serving as a backstop. # This is used only by URL previews and update/news endpoint checks # -# Defaults to 1 as generally the same open connection can be re-used -#request_idle_per_host = 1 +# Defaults to 320 seconds +#request_total_timeout = 320 # Default/base idle connection pool timeout # This is used only by URL previews and update/news endpoint checks @@ -536,6 +537,12 @@ allow_profile_lookup_federation_requests = true # Defaults to 5 seconds #request_idle_timeout = 5 +# Default/base max idle connections per host +# This is used only by URL previews and update/news endpoint checks +# +# Defaults to 1 as generally the same open connection can be re-used +#request_idle_per_host = 1 + # Federation well-known resolution connection timeout # # Defaults to 6 seconds @@ -546,21 +553,32 @@ allow_profile_lookup_federation_requests = true # Defaults to 10 seconds #well_known_timeout = 10 -# Federation client/server request timeout +# Federation client request timeout # You most definitely want this to be high to account for extremely large room joins, slow homeservers, your own resources etc. # # Defaults to 300 seconds #federation_timeout = 300 -# Federation client/sender max idle connections per host +# Federation client idle connection pool timeout +# +# Defaults to 25 seconds +#federation_idle_timeout = 25 + +# Federation client max idle connections per host # # Defaults to 1 as generally the same open connection can be re-used #federation_idle_per_host = 1 -# Federation client/sender idle connection pool timeout +# Federation sender request timeout +# The time it takes for the remote server to process sent transactions can take a while. # -# Defaults to 25 seconds -#federation_idle_timeout = 25 +# Defaults to 180 seconds +#sender_timeout = 180 + +# Federation sender idle connection pool timeout +# +# Defaults to 180 seconds +#sender_idle_timeout = 180 # Appservice URL request connection timeout # diff --git a/src/config/mod.rs b/src/config/mod.rs index ae1df429..402f0439 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -112,20 +112,22 @@ pub struct Config { pub request_conn_timeout: u64, #[serde(default = "default_request_timeout")] pub request_timeout: u64, - #[serde(default = "default_request_idle_per_host")] - pub request_idle_per_host: u16, + #[serde(default = "default_request_total_timeout")] + pub request_total_timeout: u64, #[serde(default = "default_request_idle_timeout")] pub request_idle_timeout: u64, + #[serde(default = "default_request_idle_per_host")] + pub request_idle_per_host: u16, #[serde(default = "default_well_known_conn_timeout")] pub well_known_conn_timeout: u64, #[serde(default = "default_well_known_timeout")] pub well_known_timeout: u64, #[serde(default = "default_federation_timeout")] pub federation_timeout: u64, - #[serde(default = "default_federation_idle_per_host")] - pub federation_idle_per_host: u16, #[serde(default = "default_federation_idle_timeout")] pub federation_idle_timeout: u64, + #[serde(default = "default_federation_idle_per_host")] + pub federation_idle_per_host: u16, #[serde(default = "default_sender_timeout")] pub sender_timeout: u64, #[serde(default = "default_sender_idle_timeout")] @@ -502,6 +504,7 @@ impl fmt::Display for Config { ("Maximum concurrent requests", &self.max_concurrent_requests.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()), ("Idle connections per host", &self.request_idle_per_host.to_string()), ("Request pool idle timeout", &self.request_idle_timeout.to_string()), ("Well_known connect timeout", &self.well_known_conn_timeout.to_string()), @@ -869,20 +872,22 @@ fn default_request_conn_timeout() -> u64 { 10 } fn default_request_timeout() -> u64 { 35 } -fn default_request_idle_per_host() -> u16 { 1 } +fn default_request_total_timeout() -> u64 { 320 } fn default_request_idle_timeout() -> u64 { 5 } +fn default_request_idle_per_host() -> u16 { 1 } + fn default_well_known_conn_timeout() -> u64 { 6 } fn default_well_known_timeout() -> u64 { 10 } fn default_federation_timeout() -> u64 { 300 } -fn default_federation_idle_per_host() -> u16 { 1 } - fn default_federation_idle_timeout() -> u64 { 25 } +fn default_federation_idle_per_host() -> u16 { 1 } + fn default_sender_timeout() -> u64 { 180 } fn default_sender_idle_timeout() -> u64 { 180 } diff --git a/src/service/globals/client.rs b/src/service/globals/client.rs index 3335cd16..138aa164 100644 --- a/src/service/globals/client.rs +++ b/src/service/globals/client.rs @@ -34,6 +34,7 @@ impl Client { .unwrap() .dns_resolver(resolver.hooked.clone()) .connect_timeout(Duration::from_secs(config.well_known_conn_timeout)) + .read_timeout(Duration::from_secs(config.well_known_timeout)) .timeout(Duration::from_secs(config.well_known_timeout)) .pool_max_idle_per_host(0) .redirect(redirect::Policy::limited(4)) @@ -43,6 +44,7 @@ impl Client { federation: Self::base(config) .unwrap() .dns_resolver(resolver.hooked.clone()) + .read_timeout(Duration::from_secs(config.federation_timeout)) .timeout(Duration::from_secs(config.federation_timeout)) .pool_max_idle_per_host(config.federation_idle_per_host.into()) .pool_idle_timeout(Duration::from_secs(config.federation_idle_timeout)) @@ -53,6 +55,7 @@ impl Client { sender: Self::base(config) .unwrap() .dns_resolver(resolver.hooked.clone()) + .read_timeout(Duration::from_secs(config.sender_timeout)) .timeout(Duration::from_secs(config.sender_timeout)) .pool_max_idle_per_host(1) .pool_idle_timeout(Duration::from_secs(config.sender_idle_timeout)) @@ -64,6 +67,7 @@ impl Client { .unwrap() .dns_resolver(resolver.clone()) .connect_timeout(Duration::from_secs(5)) + .read_timeout(Duration::from_secs(config.appservice_timeout)) .timeout(Duration::from_secs(config.appservice_timeout)) .pool_max_idle_per_host(1) .pool_idle_timeout(Duration::from_secs(config.appservice_idle_timeout)) @@ -90,12 +94,14 @@ impl Client { let mut builder = reqwest::Client::builder() .hickory_dns(true) - .timeout(Duration::from_secs(config.request_timeout)) .connect_timeout(Duration::from_secs(config.request_conn_timeout)) - .pool_max_idle_per_host(config.request_idle_per_host.into()) + .read_timeout(Duration::from_secs(config.request_timeout)) + .timeout(Duration::from_secs(config.request_total_timeout)) .pool_idle_timeout(Duration::from_secs(config.request_idle_timeout)) + .pool_max_idle_per_host(config.request_idle_per_host.into()) .user_agent("Conduwuit".to_owned() + "/" + &version) - .redirect(redirect::Policy::limited(6)); + .redirect(redirect::Policy::limited(6)) + .connection_verbose(true); #[cfg(feature = "gzip_compression")] {