mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-29 01:52:08 +08:00
refactor: migrate backoff crate to backon (#6718)
Replace backoff 0.4.0 with backon 1.6.0 for retry logic.
This commit is contained in:
@@ -84,7 +84,7 @@ impl CoreManager {
|
||||
#[cfg(target_os = "windows")]
|
||||
async fn wait_for_service_if_needed(&self) {
|
||||
use crate::{config::Config, constants::timing, core::service};
|
||||
use backoff::{Error as BackoffError, ExponentialBackoff};
|
||||
use backon::{ConstantBuilder, Retryable as _};
|
||||
|
||||
let needs_service = Config::verge().await.latest_arc().enable_tun_mode.unwrap_or(false);
|
||||
|
||||
@@ -92,16 +92,12 @@ impl CoreManager {
|
||||
return;
|
||||
}
|
||||
|
||||
let backoff = ExponentialBackoff {
|
||||
initial_interval: timing::SERVICE_WAIT_INTERVAL,
|
||||
max_interval: timing::SERVICE_WAIT_INTERVAL,
|
||||
max_elapsed_time: Some(timing::SERVICE_WAIT_MAX),
|
||||
multiplier: 1.0,
|
||||
randomization_factor: 0.0,
|
||||
..Default::default()
|
||||
};
|
||||
let max_times = timing::SERVICE_WAIT_MAX.as_millis() / timing::SERVICE_WAIT_INTERVAL.as_millis();
|
||||
let backoff = ConstantBuilder::default()
|
||||
.with_delay(timing::SERVICE_WAIT_INTERVAL)
|
||||
.with_max_times(max_times as usize);
|
||||
|
||||
let operation = || async {
|
||||
let _ = (|| async {
|
||||
let mut manager = SERVICE_MANAGER.lock().await;
|
||||
|
||||
if matches!(manager.current(), ServiceStatus::Ready) {
|
||||
@@ -111,19 +107,19 @@ impl CoreManager {
|
||||
// If the service IPC path is not ready yet, treat it as transient and retry.
|
||||
// Running init/refresh too early can mark service state unavailable and break later config reloads.
|
||||
if !service::is_service_ipc_path_exists() {
|
||||
return Err(BackoffError::transient(anyhow::anyhow!("Service IPC not ready")));
|
||||
return Err(anyhow::anyhow!("Service IPC not ready"));
|
||||
}
|
||||
|
||||
manager.init().await.map_err(BackoffError::transient)?;
|
||||
manager.init().await?;
|
||||
let _ = manager.refresh().await;
|
||||
|
||||
if matches!(manager.current(), ServiceStatus::Ready) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(BackoffError::transient(anyhow::anyhow!("Service not ready")))
|
||||
Err(anyhow::anyhow!("Service not ready"))
|
||||
}
|
||||
};
|
||||
|
||||
let _ = backoff::future::retry(backoff, operation).await;
|
||||
})
|
||||
.retry(backoff)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user