diff --git a/client/src/main.rs b/client/src/main.rs index 376422a..057a7a1 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -200,6 +200,16 @@ async fn main() -> anyhow::Result<()> { if error.to_string().contains(REGION_NOT_FOUND) { return; } + if error + .to_string() + .contains("Session did not reconnect within 15s") + { + error!( + "Session lost for profile {}. Waiting for a fresh tunnel endpoint...", + profile.0 + ); + return; + } error!("{}", error); } _ => {} @@ -251,6 +261,16 @@ async fn main() -> anyhow::Result<()> { .await; } Err(error) => { + if error + .to_string() + .contains("Session did not reconnect within 15s") + { + error!( + "Session lost for profile {}. Reconnecting tunnel...", + profile.0 + ); + break; + } error!("{}", error); } _ => {} diff --git a/client/src/task.rs b/client/src/task.rs index 8c0586b..85f8817 100644 --- a/client/src/task.rs +++ b/client/src/task.rs @@ -2,6 +2,7 @@ use crate::config::Profile; use crate::http::{close, download, sync}; use common::http::{CloseRequest, DownloadRequest}; use communicator::ClientManager; +use anyhow::anyhow; use log::{error, info}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -64,30 +65,42 @@ pub async fn run( id: id.clone(), task: task.clone(), }; - let result = download(&mut client.get_client().await.unwrap(), &req, &p1).await; - if let Err(e) = result - && let Some(_) = e.downcast_ref::() + let mut conn = client.get_client().await?; + let mut result = download(&mut conn, &req, &p1).await; + if let Err(e) = &result + && e.downcast_ref::().is_some() { - download(&mut client.get_client().await.unwrap(), &req, &p1) - .await - .unwrap(); + let mut retry_conn = client.get_client().await?; + result = download(&mut retry_conn, &req, &p1).await; } + result?; local_manifest .add_bundle(task.bundle_path.clone(), task.bundle_hash.clone()) .await - .unwrap(); + ?; drop(permit); + Ok::<(), anyhow::Error>(()) }); } let mut succeed = 0; let mut failed = 0; while let Some(r) = join_set.join_next().await { - if let Err(e) = r { - error!("{}", e); - failed += 1; - } else { - succeed += 1; + match r { + Ok(Ok(())) => { + succeed += 1; + } + Ok(Err(e)) => { + if e.to_string().contains("Session did not reconnect within 15s") { + return Err(anyhow!(e)); + } + error!("{}", e); + failed += 1; + } + Err(e) => { + error!("{}", e); + failed += 1; + } } } local_manifest.save().await?;