From f335f45017566447a2524604587c66c5c378191e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 23 Jul 2025 17:46:43 +0100 Subject: [PATCH] feat(policy-server): Add configurable timeout --- conduwuit-example.toml | 16 ++++++++++++++++ src/core/config/mod.rs | 19 +++++++++++++++++++ .../rooms/event_handler/policy_server.rs | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 2fab9cdf..541050b1 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -340,6 +340,22 @@ # #federation_timeout = 300 +# MSC4284 Policy server request timeout (seconds). Generally policy +# servers should respond near instantly, however may slow down under +# load. If a policy server doesn't respond in a short amount of time, the +# room it is configured in may become unusable if this limit is set too +# high. 10 seconds is a good default, however dropping this to 3-5 seconds +# can be acceptable. +# +# Please be aware that policy requests are *NOT* currently re-tried, so if +# a spam check request fails, the event will be assumed to be not spam, +# which in some cases may result in spam being sent to or received from +# the room that would typically be prevented. +# +# About policy servers: https://matrix.org/blog/2025/04/introducing-policy-servers/ +# +#policy_server_request_timeout = 10 + # Federation client idle connection pool timeout (seconds). # #federation_idle_timeout = 25 diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 909462db..9f3d8047 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -431,6 +431,23 @@ pub struct Config { #[serde(default = "default_federation_timeout")] pub federation_timeout: u64, + /// MSC4284 Policy server request timeout (seconds). Generally policy + /// servers should respond near instantly, however may slow down under + /// load. If a policy server doesn't respond in a short amount of time, the + /// room it is configured in may become unusable if this limit is set too + /// high. 10 seconds is a good default, however dropping this to 3-5 seconds + /// can be acceptable. + /// + /// Please be aware that policy requests are *NOT* currently re-tried, so if + /// a spam check request fails, the event will be assumed to be not spam, + /// which in some cases may result in spam being sent to or received from + /// the room that would typically be prevented. + /// + /// About policy servers: https://matrix.org/blog/2025/04/introducing-policy-servers/ + /// default: 10 + #[serde(default = "default_policy_server_request_timeout")] + pub policy_server_request_timeout: u64, + /// Federation client idle connection pool timeout (seconds). /// /// default: 25 @@ -2208,6 +2225,8 @@ fn default_federation_conn_timeout() -> u64 { 10 } fn default_federation_timeout() -> u64 { 25 } +fn default_policy_server_request_timeout() -> u64 { 25 } + fn default_federation_idle_timeout() -> u64 { 25 } fn default_federation_idle_per_host() -> u16 { 1 } diff --git a/src/service/rooms/event_handler/policy_server.rs b/src/service/rooms/event_handler/policy_server.rs index 7a93d74d..debd9a28 100644 --- a/src/service/rooms/event_handler/policy_server.rs +++ b/src/service/rooms/event_handler/policy_server.rs @@ -65,7 +65,7 @@ pub async fn ask_policy_server(&self, pdu: &PduEvent, room_id: &RoomId) -> Resul "Checking event for spam with policy server" ); let response = tokio::time::timeout( - Duration::from_secs(10), + Duration::from_secs(self.services.server.config.policy_server_request_timeout), self.services .sending .send_federation_request(via, PolicyRequest {