API: Fix data race in online ipList (#4513)

Fixes https://github.com/XTLS/Xray-core/issues/4512
This commit is contained in:
风扇滑翔翼 2025-03-20 19:12:36 +08:00 committed by GitHub
parent 3d21128159
commit b70d0abebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()