From b323802ab0dbd87ec97d27ea07bb947d48ae5663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 30 Jan 2025 11:56:37 +0100 Subject: [PATCH] fix(ui): Enable retries for network failures of the /versions check in the SyncService --- crates/matrix-sdk-ui/src/sync_service.rs | 26 +++++++++++++----------- crates/matrix-sdk/src/client/mod.rs | 5 +++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index dd83b1861..cabb84173 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -32,6 +32,7 @@ use futures_util::{ pin_mut, StreamExt as _, }; use matrix_sdk::{ + config::RequestConfig, executor::{spawn, JoinHandle}, sleep::sleep, Client, @@ -174,22 +175,23 @@ impl SyncTaskSupervisor { let wait_to_be_online = async move { loop { + // Encountering network failures when sending a request which has with no retry + // limit set in the `RequestConfig` are treated as permanent failures and our + // exponential backoff doesn't kick in. + // + // Let's set a retry limit so network failures are retried as well. + let request_config = RequestConfig::default().retry_limit(5); + // We're in an infinite loop, but our request sending already has an exponential // backoff set up. This will kick in for any request errors that we consider to - // be transient. Common network errors (timeouts, DNS failures) - // or any server error in the 5xx range of HTTP errors are - // considered to be transient. + // be transient. Common network errors (timeouts, DNS failures) or any server + // error in the 5xx range of HTTP errors are considered to be transient. // - // This means that we're not going to tightloop here, and in the case the - // `RequestConfig` has been set up to not have a limit, ever hit the second - // iteration of this loop. - // - // No matter, as a precaution, we're going to sleep for a while here in the - // Error case, the user might have configured the RequestConfig - // to not contain any backoff or retries. - match client.fetch_server_capabilities().await { + // Still, as a precaution, we're going to sleep here for a while in the Error + // case. + match client.fetch_server_capabilities(Some(request_config)).await { Ok(_) => break, - Err(_) => sleep(Duration::from_millis(500)).await, + Err(_) => sleep(Duration::from_millis(100)).await, } } }; diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index d97198e2c..cb69f808d 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1653,13 +1653,14 @@ impl Client { /// Fetches server capabilities from network; no caching. pub async fn fetch_server_capabilities( &self, + request_config: Option, ) -> HttpResult<(Box<[MatrixVersion]>, BTreeMap)> { let resp = self .inner .http_client .send( get_supported_versions::Request::new(), - None, + request_config, self.homeserver().to_string(), None, &[MatrixVersion::V1_0], @@ -1698,7 +1699,7 @@ impl Client { } } - let (versions, unstable_features) = self.fetch_server_capabilities().await?; + let (versions, unstable_features) = self.fetch_server_capabilities(None).await?; // Attempt to cache the result in storage. {