From 74411707e79da20404e783d67503968782bedbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=83=E9=9A=A8=E7=B7=A3=E5=8B=95?= Date: Wed, 10 Sep 2025 16:41:06 +0800 Subject: [PATCH] v2.7.2 --- xray/process.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xray/process.go b/xray/process.go index 21ca5223..33700aad 100644 --- a/xray/process.go +++ b/xray/process.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "runtime" + "sync" "syscall" "time" @@ -102,6 +103,7 @@ type process struct { apiPort int onlineClients []string + mutex sync.RWMutex config *Config logWriter *LogWriter @@ -152,11 +154,17 @@ func (p *Process) GetConfig() *Config { } func (p *Process) GetOnlineClients() []string { - return p.onlineClients + p.mutex.RLock() + defer p.mutex.RUnlock() + clientsCopy := make([]string, len(p.onlineClients)) + copy(clientsCopy, p.onlineClients) + return clientsCopy } -func (p *Process) SetOnlineClients(users []string) { - p.onlineClients = users +func (p *Process) SetOnlineClients(clients []string) { + p.mutex.Lock() + defer p.mutex.Unlock() + p.onlineClients = clients } func (p *Process) GetUptime() uint64 {