Skip to content

Commit

Permalink
Merge pull request #55 from hnez/rauc-bundle-polling-wait
Browse files Browse the repository at this point in the history
rauc: perform retries with exponential backoff
  • Loading branch information
hnez committed May 24, 2024
2 parents e1e6ef5 + 9d0e394 commit 8bc7030
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/dbus/rauc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ mod imports {
}

const RELOAD_RATE_LIMIT: Duration = Duration::from_secs(10 * 60);
const RETRY_INTERVAL_MIN: Duration = Duration::from_secs(60);
const RETRY_INTERVAL_MAX: Duration = Duration::from_secs(60 * 60);

use imports::*;

Expand Down Expand Up @@ -188,6 +190,8 @@ async fn channel_polling_task(
) {
let proxy = InstallerProxy::new(&conn).await.unwrap();

let mut retry_interval = RETRY_INTERVAL_MIN;

while let Some(mut channel) = channels
.try_get()
.and_then(|chs| chs.into_iter().find(|ch| ch.name == name))
Expand All @@ -201,11 +205,26 @@ async fn channel_polling_task(

if let Err(e) = channel.poll(&proxy, slot_status.as_deref()).await {
warn!(
"Failed to fetch update for update channel \"{}\": {}",
channel.name, e
"Failed to fetch update for update channel \"{}\": {}. Retrying in {}s.",
channel.name,
e,
retry_interval.as_secs()
);

if retry_interval < RETRY_INTERVAL_MAX {
sleep(retry_interval).await;

// Perform a (limited) exponential backoff on the retry interval to recover
// fast from short-term issues while also preventing the update server from
// being DDOSed by excessive retries.
retry_interval *= 2;

continue;
}
}

retry_interval = RETRY_INTERVAL_MIN;

channels.modify(|chs| {
let mut chs = chs?;
let channel_prev = chs.iter_mut().find(|ch| ch.name == name)?;
Expand Down

0 comments on commit 8bc7030

Please sign in to comment.