updater: apply exponential backoff after download failure (#8059)
* updater: apply exponential backoff after download failure * updater: reset backoff on new release
This commit is contained in:
parent
f54944bbfc
commit
f48b09b76e
@ -18,6 +18,7 @@ use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{PathBuf};
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use ethcore::client::{BlockId, BlockChainClient, ChainNotify};
|
||||
use ethsync::{SyncProvider};
|
||||
@ -82,6 +83,8 @@ struct UpdaterState {
|
||||
capability: CapState,
|
||||
|
||||
disabled: bool,
|
||||
|
||||
backoff: Option<(u32, Instant)>,
|
||||
}
|
||||
|
||||
/// Service for checking for updates and determining whether we can achieve consensus.
|
||||
@ -260,7 +263,19 @@ impl Updater {
|
||||
let fetched = s.fetching.take().unwrap();
|
||||
let dest = self.updates_path(&Self::update_file_name(&fetched.version));
|
||||
if !dest.exists() {
|
||||
let b = result.map_err(|e| (format!("Unable to fetch update ({}): {:?}", fetched.version, e), false))?;
|
||||
let b = match result {
|
||||
Ok(b) => {
|
||||
s.backoff = None;
|
||||
b
|
||||
},
|
||||
Err(e) => {
|
||||
let mut n = s.backoff.map(|b| b.0 + 1).unwrap_or(1);
|
||||
s.backoff = Some((n, Instant::now() + Duration::from_secs(2usize.pow(n) as u64)));
|
||||
|
||||
return Err((format!("Unable to fetch update ({}): {:?}", fetched.version, e), false));
|
||||
},
|
||||
};
|
||||
|
||||
info!(target: "updater", "Fetched latest version ({}) OK to {}", fetched.version, b.display());
|
||||
fs::create_dir_all(dest.parent().expect("at least one thing pushed; qed")).map_err(|e| (format!("Unable to create updates path: {:?}", e), true))?;
|
||||
fs::copy(&b, &dest).map_err(|e| (format!("Unable to copy update: {:?}", e), true))?;
|
||||
@ -320,6 +335,7 @@ impl Updater {
|
||||
drop(s);
|
||||
self.fetch_done(Ok(PathBuf::new()));
|
||||
} else {
|
||||
if s.backoff.iter().all(|&(_, instant)| Instant::now() >= instant) {
|
||||
info!(target: "updater", "Attempting to get parity binary {}", b);
|
||||
s.fetching = Some(latest.track.clone());
|
||||
drop(s);
|
||||
@ -330,6 +346,7 @@ impl Updater {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
trace!(target: "updater", "Fork: this/current/latest/latest-known: {}/#{}/#{}/#{}", match latest.this_fork { Some(f) => format!("#{}", f), None => "unknown".into(), }, current_number, latest.track.fork, latest.fork);
|
||||
|
||||
if let Some(this_fork) = latest.this_fork {
|
||||
@ -354,6 +371,11 @@ impl Updater {
|
||||
}
|
||||
|
||||
let mut s = self.state.lock();
|
||||
|
||||
if s.latest != latest {
|
||||
s.backoff = None;
|
||||
}
|
||||
|
||||
s.latest = latest;
|
||||
s.capability = capability;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user