fix: make offline detection less aggressive

- Increase network check timeout from 5s to 15s
- Add retry (2 attempts with 2s delay) before declaring offline
- Add logging for failed network check attempts

This prevents false offline mode triggers from temporary latency spikes.
This commit is contained in:
vicrodh committed 2026-01-16 19:24:35 -06:00
1 parent c5a1d14822
commit 6e36b56486
1 file changed
+24 -6
+24 -6
View File
@@ -437,10 +437,12 @@ impl OfflineState {
}
}
/// Check network connectivity by attempting to reach Qobuz API
/// Check network connectivity by attempting to reach Qobuz API.
/// Uses a longer timeout (15s) and retries once before declaring offline
/// to avoid false positives from temporary latency spikes.
pub async fn check_network_connectivity() -> bool {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(15))
.build();
let client = match client {
@@ -448,11 +450,27 @@ pub async fn check_network_connectivity() -> bool {
Err(_) => return false,
};
// Use HEAD request for minimal data transfer
match client.head("https://www.qobuz.com").send().await {
Ok(response) => response.status().is_success() || response.status().is_redirection(),
Err(_) => false,
// Try up to 2 times before declaring offline
for attempt in 1..=2 {
match client.head("https://www.qobuz.com").send().await {
Ok(response) => {
if response.status().is_success() || response.status().is_redirection() {
return true;
}
}
Err(e) => {
log::warn!("Network check attempt {} failed: {}", attempt, e);
}
}
// Wait 2 seconds before retry
if attempt < 2 {
tokio::time::sleep(Duration::from_secs(2)).await;
}
}
log::info!("Network connectivity check failed after 2 attempts");
false
}
// Tauri commands