Skip to content

Commit

Permalink
fix: auto update continuously checks auto_update_check_interval is di…
Browse files Browse the repository at this point in the history
…sabled (#3270)

Description
---
Continuously checks for updates when auto_update_check_interval is disabled.

Thanks @mikethetike. for finding it and for the fix 

Add check to if no auto update URIs are configured 

Motivation and Context
---
Bug fix

When check_interval is disabled, stream::empty() is used to disable the update checking, however it
returns None continuously when polled, causing the update to continuously be checked.

Also sets MissedTickBehaviour::Skip - which will prevent bursts of checks if intervals are missed

How Has This Been Tested?
---
Ran base node with auto_update_check_interval = 0 (or equivalently without this setting set)
  • Loading branch information
sdbondi authored Aug 31, 2021
1 parent 7249ce4 commit b3bff31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion base_layer/p2p/src/auto_update/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::{
use tari_common::configuration::bootstrap::ApplicationType;
use tari_utilities::hex::{from_hex, Hex};

const LOG_TARGET: &str = "p2p::auto-update:dns";
const LOG_TARGET: &str = "p2p::auto_update::dns";

pub struct DnsSoftwareUpdate {
client: DnsClient,
Expand Down
8 changes: 7 additions & 1 deletion base_layer/p2p/src/auto_update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::{
use tari_common::configuration::bootstrap::ApplicationType;
use tari_utilities::hex::Hex;

const LOG_TARGET: &str = "p2p::auto-update";
const LOG_TARGET: &str = "p2p::auto_update";

#[derive(Debug, Clone)]
pub struct AutoUpdateConfig {
Expand All @@ -58,6 +58,12 @@ pub struct AutoUpdateConfig {
pub hashes_sig_url: String,
}

impl AutoUpdateConfig {
pub fn is_update_enabled(&self) -> bool {
!self.update_uris.is_empty()
}
}

pub async fn check_for_updates(
app: ApplicationType,
arch: &str,
Expand Down
19 changes: 16 additions & 3 deletions base_layer/p2p/src/auto_update/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ use crate::{
auto_update::{AutoUpdateConfig, SoftwareUpdate, Version},
};
use futures::{future::Either, stream, StreamExt};
use log::*;
use std::{env::consts, time::Duration};
use tari_common::configuration::bootstrap::ApplicationType;
use tari_service_framework::{async_trait, ServiceInitializationError, ServiceInitializer, ServiceInitializerContext};
use tokio::{
sync::{mpsc, oneshot, watch},
time,
time::MissedTickBehavior,
};
use tokio_stream::wrappers;

const LOG_TARGET: &str = "app:auto-update";
const LOG_TARGET: &str = "p2p::auto_update";

/// A watch notifier that contains the latest software update, if any
pub type SoftwareUpdateNotifier = watch::Receiver<Option<SoftwareUpdate>>;
Expand Down Expand Up @@ -92,7 +94,11 @@ impl SoftwareUpdaterService {
new_update_notification: watch::Receiver<Option<SoftwareUpdate>>,
) {
let mut interval_or_never = match self.check_interval {
Some(interval) => Either::Left(wrappers::IntervalStream::new(time::interval(interval))),
Some(interval) => {
let mut interval = time::interval(interval);
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
Either::Left(wrappers::IntervalStream::new(interval))
},
None => Either::Right(stream::empty()),
};

Expand All @@ -106,7 +112,7 @@ impl SoftwareUpdaterService {
maybe_update
},

_ = interval_or_never.next() => {
Some(_) = interval_or_never.next() => {
// Periodically, check for updates if configured to do so.
// If an update is found the new update notifier will be triggered and any listeners notified
self.check_for_updates().await
Expand All @@ -132,6 +138,13 @@ impl SoftwareUpdaterService {
"Checking for updates ({})...",
self.config.update_uris.join(", ")
);
if !self.config.is_update_enabled() {
warn!(
target: LOG_TARGET,
"Check for updates has been called but auto update has been disabled in the config"
);
return None;
}

let arch = format!("{}-{}", consts::OS, consts::ARCH);

Expand Down

0 comments on commit b3bff31

Please sign in to comment.