From f7486029e24dabd2b04af0177bf1b6213c684814 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Thu, 17 Aug 2023 22:56:04 +0530 Subject: [PATCH 1/3] fix: downloader thread error out without logline --- uplink/src/collector/downloader.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 3249fcb1..5e8d61ae 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -139,15 +139,21 @@ impl FileDownloader { /// Spawn a thread to handle downloading files as notified by download actions and for forwarding the updated actions /// back to bridge for further processing, e.g. OTA update installation. #[tokio::main(flavor = "current_thread")] - pub async fn start(mut self) -> Result<(), Error> { + pub async fn start(mut self) { let routes = &self.config.actions; let download_rx = match self.bridge_tx.register_action_routes(routes).await { Some(r) => r, - _ => return Ok(()), + _ => return, }; loop { self.sequence = 0; - let action = download_rx.recv_async().await?; + let action = match download_rx.recv_async().await { + Ok(a) => a, + Err(e) => { + error!("Downloader thread had to stop: {e}"); + break; + } + }; self.action_id = action.action_id.clone(); let duration = match self.timeouts.get(&action.name) { @@ -382,7 +388,7 @@ mod test { let downloader = FileDownloader::new(Arc::new(config), bridge_tx).unwrap(); // Start FileDownloader in separate thread - std::thread::spawn(|| downloader.start().unwrap()); + std::thread::spawn(|| downloader.start()); // Create a firmware update action let download_update = DownloadFile { @@ -458,7 +464,7 @@ mod test { let downloader = FileDownloader::new(Arc::new(config), bridge_tx).unwrap(); // Start FileDownloader in separate thread - std::thread::spawn(|| downloader.start().unwrap()); + std::thread::spawn(|| downloader.start()); // Create a firmware update action let download_update = DownloadFile { From d909032618c10213ab9d26e629cf6e88193f4838 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Thu, 17 Aug 2023 23:04:55 +0530 Subject: [PATCH 2/3] log: add info line on starting downloader --- uplink/src/collector/downloader.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 5e8d61ae..cd9b6e4b 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -145,6 +145,8 @@ impl FileDownloader { Some(r) => r, _ => return, }; + + info!("Downloader thread is ready to receive download actions"); loop { self.sequence = 0; let action = match download_rx.recv_async().await { From 0e49a57602a6fadd9fa9412b2f205db7622afc34 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Thu, 17 Aug 2023 23:05:37 +0530 Subject: [PATCH 3/3] chore: rm unnecessary error variant --- uplink/src/collector/downloader.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index cd9b6e4b..91717d04 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -48,7 +48,6 @@ //! [`action_redirections`]: Config#structfield.action_redirections use bytes::BytesMut; -use flume::RecvError; use futures_util::StreamExt; use log::{error, info, warn}; use reqwest::{Certificate, Client, ClientBuilder, Identity, Response}; @@ -78,8 +77,6 @@ pub enum Error { Reqwest(#[from] reqwest::Error), #[error("File io Error: {0}")] Io(#[from] std::io::Error), - #[error("Error receiving action: {0}")] - Recv(#[from] RecvError), #[error("Empty file name")] EmptyFileName, #[error("Missing file path")]