From b3bff31cb5c81a0439f28f30385074c3123a157b Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Tue, 31 Aug 2021 14:10:40 +0400 Subject: [PATCH] fix: auto update continuously checks auto_update_check_interval is disabled (#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) --- base_layer/p2p/src/auto_update/dns.rs | 2 +- base_layer/p2p/src/auto_update/mod.rs | 8 +++++++- base_layer/p2p/src/auto_update/service.rs | 19 ++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/base_layer/p2p/src/auto_update/dns.rs b/base_layer/p2p/src/auto_update/dns.rs index 64c3be7f5a..63fb4ed05e 100644 --- a/base_layer/p2p/src/auto_update/dns.rs +++ b/base_layer/p2p/src/auto_update/dns.rs @@ -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, diff --git a/base_layer/p2p/src/auto_update/mod.rs b/base_layer/p2p/src/auto_update/mod.rs index 21de03b693..8ce17b5f2b 100644 --- a/base_layer/p2p/src/auto_update/mod.rs +++ b/base_layer/p2p/src/auto_update/mod.rs @@ -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 { @@ -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, diff --git a/base_layer/p2p/src/auto_update/service.rs b/base_layer/p2p/src/auto_update/service.rs index eebd9ec555..a235ec6fe0 100644 --- a/base_layer/p2p/src/auto_update/service.rs +++ b/base_layer/p2p/src/auto_update/service.rs @@ -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>; @@ -92,7 +94,11 @@ impl SoftwareUpdaterService { new_update_notification: watch::Receiver>, ) { 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()), }; @@ -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 @@ -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);