API: Fix data race in online ipList

This commit is contained in:
风扇滑翔翼 2025-03-20 06:09:15 +00:00 committed by GitHub
parent 2cba2c4d59
commit e866ce187f
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()