fix(ui): Enable retries for network failures of the /versions check in the SyncService

This commit is contained in:
Damir Jelić
2025-01-30 11:56:37 +01:00
parent 252786d2ef
commit b323802ab0
2 changed files with 17 additions and 14 deletions

View File

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

View File

@@ -1653,13 +1653,14 @@ impl Client {
/// Fetches server capabilities from network; no caching.
pub async fn fetch_server_capabilities(
&self,
request_config: Option<RequestConfig>,
) -> HttpResult<(Box<[MatrixVersion]>, BTreeMap<String, bool>)> {
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.
{