Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(updater): remove total download deadline and add stream chunk retry
Samir Hossainse0002b9557fa
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b2443f7..461f5a4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@- Automated Scoop manifest synchronization alongside Homebrew in `.github/workflows/manifests.yml`, extracting `MovieBox_Windows_x64.zip` and `MovieBox_Windows_arm64.zip` checksums from `SHA256SUMS`.- Added `InstallationEnvironment::Scoop` detection in `src/updater/apply.rs` via executable path inspection (`/scoop/apps/`, `\scoop\apps\`, `/scoop/shims/`, `\scoop\shims\`).- Added dedicated update notification modal handling with `[s]` shortcut to display `scoop update moviebox-tui` on Scoop-managed Windows installations.+### Fixed+- **In-App Updater Streaming Timeout & Chunk Retry Recovery**:+ - Removed the static 30-second total request deadline from the release binary download client in `src/updater/check.rs`, preventing mid-transfer decode aborts (`download chunk stream error: error decoding response body`) on slow or high-latency network connections.+ - Added mid-stream chunk failure recovery in `src/updater/download.rs` with automatic temporary file cleanup, exponential backoff, and retry loop up to 3 attempts.## [0.1.23] - 2026-09-21### Fixeddiff --git a/src/updater/check.rs b/src/updater/check.rsindex 01f8188..2230539 100644--- a/src/updater/check.rs+++ b/src/updater/check.rs@@ -111,7 +111,6 @@ async fn fetch_latest_tag() -> Result<String, String> {}Ok(tag.to_string())}-pub(crate) fn http_client() -> Result<reqwest::Client, String> {crate::net::http_client_builder().user_agent("MovieBox-Tui")@@ -120,3 +119,11 @@ pub(crate) fn http_client() -> Result<reqwest::Client, String> {.build().map_err(|e| format!("HTTP client: {e}"))}++pub(crate) fn download_client() -> Result<reqwest::Client, String> {+ crate::net::http_client_builder()+ .user_agent("MovieBox-Tui")+ .connect_timeout(std::time::Duration::from_secs(15))+ .build()+ .map_err(|e| format!("Download client: {e}"))+}diff --git a/src/updater/download.rs b/src/updater/download.rsindex b2c5644..9b5f5f2 100644--- a/src/updater/download.rs+++ b/src/updater/download.rs@@ -1,6 +1,9 @@use std::path::Path;-use super::check::http_client;+use futures::StreamExt;+use tokio::io::AsyncWriteExt;++use super::check::{download_client, http_client};pub async fn download_file(url: &str, destination: &Path) -> Result<(), String> {if !url.starts_with("https://")@@ -10,60 +13,14 @@ pub async fn download_file(url: &str, destination: &Path) -> Result<(), String>return Err("refusing non-https download url".to_string());}- let client = http_client()?;+ let client = download_client()?;let mut attempts = 0;let max_attempts = 3;loop {attempts += 1;- match client.get(url).send().await {- Ok(resp) => {- if !resp.status().is_success() {- let status = resp.status();- if attempts < max_attempts- && (status.is_server_error()- || status == reqwest::StatusCode::REQUEST_TIMEOUT)- {- tokio::time::sleep(std::time::Duration::from_millis(500 * attempts as u64))- .await;- continue;- }- return Err(format!("download failed with status {status}"));- }-- use futures::StreamExt;- use tokio::io::AsyncWriteExt;-- let mut file = tokio::fs::File::create(destination)- .await- .map_err(|e| format!("failed to create temp download file: {e}"))?;-- let mut stream = resp.bytes_stream();- let mut write_err = None;- while let Some(chunk_res) = stream.next().await {- match chunk_res {- Ok(chunk) => {- if let Err(e) = file.write_all(&chunk).await {- write_err = Some(format!("failed to write download data: {e}"));- break;- }- }- Err(e) => {- write_err = Some(format!("download chunk stream error: {e}"));- break;- }- }- }- if let Some(err) = write_err {- let _ = tokio::fs::remove_file(destination).await;- return Err(err);- }- if let Err(e) = file.flush().await {- let _ = tokio::fs::remove_file(destination).await;- return Err(format!("failed to flush download file: {e}"));- }- return Ok(());- }+ let resp = match client.get(url).send().await {+ Ok(resp) => resp,Err(e) => {if attempts < max_attempts {tokio::time::sleep(std::time::Duration::from_millis(500 * attempts as u64))@@ -72,7 +29,60 @@ pub async fn download_file(url: &str, destination: &Path) -> Result<(), String>}return Err(format!("download network error: {e}"));}+ };++ if !resp.status().is_success() {+ let status = resp.status();+ if attempts < max_attempts+ && (status.is_server_error() || status == reqwest::StatusCode::REQUEST_TIMEOUT)+ {+ tokio::time::sleep(std::time::Duration::from_millis(500 * attempts as u64)).await;+ continue;+ }+ return Err(format!("download failed with status {status}"));+ }++ let mut file = match tokio::fs::File::create(destination).await {+ Ok(f) => f,+ Err(e) => return Err(format!("failed to create temp download file: {e}")),+ };++ let mut stream = resp.bytes_stream();+ let mut write_err = None;++ while let Some(chunk_res) = stream.next().await {+ match chunk_res {+ Ok(chunk) => {+ if let Err(e) = file.write_all(&chunk).await {+ write_err = Some(format!("failed to write download data: {e}"));+ break;+ }+ }+ Err(e) => {+ write_err = Some(format!("download chunk stream error: {e}"));+ break;+ }+ }}++ if let Some(err) = write_err {+ let _ = tokio::fs::remove_file(destination).await;+ if attempts < max_attempts {+ log::warn!(+ "updater download chunk failed (attempt {attempts}/{max_attempts}): {err}; retrying"+ );+ tokio::time::sleep(std::time::Duration::from_millis(500 * attempts as u64)).await;+ continue;+ }+ return Err(err);+ }++ if let Err(e) = file.flush().await {+ let _ = tokio::fs::remove_file(destination).await;+ return Err(format!("failed to flush download file: {e}"));+ }++ return Ok(());}}