From b70d0abebe393b1296aa1934eca0751692f8cc73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Thu, 20 Mar 2025 19:12:36 +0800 Subject: [PATCH] API: Fix data race in online ipList (#4513) Fixes https://github.com/XTLS/Xray-core/issues/4512 --- app/stats/online_map.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/stats/online_map.go b/app/stats/online_map.go index 9505b28b..7cc6ac96 100644 --- a/app/stats/online_map.go +++ b/app/stats/online_map.go @@ -40,11 +40,11 @@ func (c *OnlineMap) AddIP(ip string) { if ip == "127.0.0.1" { return } + c.access.Lock() if _, ok := list[ip]; !ok { - c.access.Lock() list[ip] = time.Now() - c.access.Unlock() } + c.access.Unlock() if time.Since(c.lastCleanup) > c.cleanupPeriod { list = c.RemoveExpiredIPs(list) c.lastCleanup = time.Now()