fix: serialize concurrent configuration updates

This commit is contained in:
wonfen
2026-08-17 19:19:54 +08:00
parent 95ae5e4e71
commit 906ec5e63a
5 changed files with 55 additions and 91 deletions
+7 -1
View File
@@ -23,7 +23,7 @@ use std::{
path::PathBuf,
sync::atomic::{AtomicBool, Ordering},
};
use tokio::sync::OnceCell;
use tokio::sync::{Mutex, MutexGuard, OnceCell};
use tokio::time::sleep;
pub struct Config {
@@ -34,6 +34,7 @@ pub struct Config {
}
static TUN_SESSION_SUPPRESSED: AtomicBool = AtomicBool::new(false);
static CONFIG_WRITE_LOCK: Mutex<()> = Mutex::const_new(());
impl Config {
pub async fn global() -> &'static Self {
@@ -66,6 +67,11 @@ impl Config {
Self::global().await.runtime_config.clone()
}
/// Serialize transactions that share configuration draft layers.
pub(crate) async fn lock_config_write() -> MutexGuard<'static, ()> {
CONFIG_WRITE_LOCK.lock().await
}
/// 初始化订阅
pub async fn init_config() -> Result<()> {
Self::init_config_before_window().await?;