Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: downloader thread error out without logline #270

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions uplink/src/collector/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -139,15 +136,23 @@ 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,
};

info!("Downloader thread is ready to receive download actions");
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) {
Expand Down Expand Up @@ -382,7 +387,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 {
Expand Down Expand Up @@ -458,7 +463,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 {
Expand Down
Loading