From 5399ac97f268639444d1a83bf65a479b91927add Mon Sep 17 00:00:00 2001 From: rooot Date: Sun, 20 Jul 2025 03:14:35 +0200 Subject: [PATCH] feat(config): introduce federation connection timeout setting fixes #906 Signed-off-by: rooot --- conduwuit-example.toml | 7 +++++++ src/core/config/mod.rs | 11 +++++++++++ src/service/client/mod.rs | 3 +++ 3 files changed, 21 insertions(+) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index bdc2f570..255de196 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -325,6 +325,13 @@ # #well_known_timeout = 10 +# Federation client connection timeout (seconds). You should not set this +# to high values, as dead homeservers can significantly slow down federation, +# specifically key retrieval, which will take roughly the amount of time +# you configure here given that a homeserver doesn't respond. +# +#federation_conn_timeout = 10 + # Federation client request timeout (seconds). You most definitely want # this to be high to account for extremely large room joins, slow # homeservers, your own resources etc. diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index d93acd9b..7ae2dc6e 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -412,6 +412,15 @@ pub struct Config { #[serde(default = "default_well_known_timeout")] pub well_known_timeout: u64, + /// Federation client connection timeout (seconds). You should not set this + /// to high values, as dead homeservers can significantly slow down federation, + /// specifically key retrieval, which will take roughly the amount of time + /// you configure here given that a homeserver doesn't respond. + /// + /// default: 10 + #[serde(default = "default_federation_conn_timeout")] + pub federation_conn_timeout: u64, + /// Federation client request timeout (seconds). You most definitely want /// this to be high to account for extremely large room joins, slow /// homeservers, your own resources etc. @@ -2193,6 +2202,8 @@ fn default_well_known_conn_timeout() -> u64 { 6 } fn default_well_known_timeout() -> u64 { 10 } +fn default_federation_conn_timeout() -> u64 { 10 } + fn default_federation_timeout() -> u64 { 25 } fn default_federation_idle_timeout() -> u64 { 25 } diff --git a/src/service/client/mod.rs b/src/service/client/mod.rs index 1aeeb492..239340ba 100644 --- a/src/service/client/mod.rs +++ b/src/service/client/mod.rs @@ -66,6 +66,7 @@ impl crate::Service for Service { federation: base(config)? .dns_resolver(resolver.resolver.hooked.clone()) + .connect_timeout(Duration::from_secs(config.federation_conn_timeout)) .read_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)) @@ -74,6 +75,7 @@ impl crate::Service for Service { synapse: base(config)? .dns_resolver(resolver.resolver.hooked.clone()) + .connect_timeout(Duration::from_secs(config.federation_conn_timeout)) .read_timeout(Duration::from_secs(305)) .pool_max_idle_per_host(0) .redirect(redirect::Policy::limited(3)) @@ -81,6 +83,7 @@ impl crate::Service for Service { sender: base(config)? .dns_resolver(resolver.resolver.hooked.clone()) + .connect_timeout(Duration::from_secs(config.federation_conn_timeout)) .read_timeout(Duration::from_secs(config.sender_timeout)) .timeout(Duration::from_secs(config.sender_timeout)) .pool_max_idle_per_host(1)