mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-17 17:32:15 +08:00
fix(service): fail fast when the Windows service is stopped
A registered but stopped service made every version probe back off for about two minutes, blocking startup before the window and core (#8059). Check the SCM first; a service that is starting, or not yet started this boot, still goes through the IPC retries.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
- 修复 Windows 部分未安装服务的用户以普通权限运行时,内核无法启动的问题
|
||||
- 修复 Windows 系统隔离权限被误判,导致服务模式和 TUN 无法使用的问题
|
||||
- 修复 Windows 旧版服务状态残留导致无法重装的问题,自动备份可识别的残留并恢复安装
|
||||
- 修复 Windows 服务已停止时,启动要等约两分钟才显示窗口的问题
|
||||
- 优化 Windows 服务安全检查失败提示:用易懂的文字说明原因,并提供修复文档链接
|
||||
|
||||
**🍎 macOS**
|
||||
|
||||
@@ -27,6 +27,14 @@ pub struct RealEnv;
|
||||
|
||||
impl RunStateEnv for RealEnv {
|
||||
async fn probe_service_version(&self) -> Result<ServiceVersionReply> {
|
||||
// The IPC client would otherwise back off for about two minutes before failing.
|
||||
#[cfg(windows)]
|
||||
if tokio::task::spawn_blocking(crate::core::service::service_stopped)
|
||||
.await
|
||||
.context("service status probe did not finish")??
|
||||
{
|
||||
anyhow::bail!("the Windows service is not running");
|
||||
}
|
||||
let response = clash_verge_service_ipc::get_version().await?;
|
||||
let core = if response.code == 0
|
||||
&& response.data.as_ref().is_some_and(|info| {
|
||||
|
||||
@@ -242,7 +242,7 @@ fn macos_service_install_marker_exists() -> std::io::Result<bool> {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn trusted_service_evidence() -> Result<bool> {
|
||||
fn open_registered_service() -> Result<Option<windows_service::service::Service>> {
|
||||
use windows_service::{
|
||||
Error as WindowsServiceError,
|
||||
service::ServiceAccess,
|
||||
@@ -255,17 +255,36 @@ pub(crate) fn trusted_service_evidence() -> Result<bool> {
|
||||
clash_verge_service_ipc::WINDOWS_SERVICE_NAME,
|
||||
ServiceAccess::QUERY_STATUS,
|
||||
) {
|
||||
Ok(service) => {
|
||||
drop(service);
|
||||
Ok(true)
|
||||
}
|
||||
Ok(service) => Ok(Some(service)),
|
||||
Err(WindowsServiceError::Winapi(error)) if error.raw_os_error() == Some(ERROR_SERVICE_DOES_NOT_EXIST) => {
|
||||
Ok(false)
|
||||
Ok(None)
|
||||
}
|
||||
Err(error) => Err(error).context("failed to inspect Windows service registration"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn trusted_service_evidence() -> Result<bool> {
|
||||
Ok(open_registered_service()?.is_some())
|
||||
}
|
||||
|
||||
/// Whether IPC cannot succeed until the service is started again. A service that is starting, or
|
||||
/// that the SCM has not started yet this boot, is left to the IPC retries, which wait for it.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn service_stopped() -> Result<bool> {
|
||||
use windows_service::service::{ServiceExitCode, ServiceState};
|
||||
|
||||
const ERROR_SERVICE_NEVER_STARTED: u32 = 1077;
|
||||
let Some(service) = open_registered_service()? else {
|
||||
return Ok(true);
|
||||
};
|
||||
let status = service
|
||||
.query_status()
|
||||
.context("failed to query Windows service status")?;
|
||||
Ok(status.current_state == ServiceState::Stopped
|
||||
&& status.exit_code != ServiceExitCode::Win32(ERROR_SERVICE_NEVER_STARTED))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn trusted_service_evidence() -> Result<bool> {
|
||||
let unit = format!("{}.service", clash_verge_service_ipc::SERVICE_SLUG);
|
||||
|
||||
Reference in New Issue
Block a user