Skip to content

Commit

Permalink
Lock whole delete loop to prevent concurrent access
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwr committed Mar 21, 2019
1 parent 90506ef commit b909143
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions map_limit_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func NewMapLimitStore(expirationTime time.Duration, flushInterval time.Duration)
go func() {
ticker := time.NewTicker(flushInterval)
for range ticker.C {
m.mutex.Lock()
for key, val := range m.data {
if val.lastUpdate.Before(time.Now().UTC().Add(-m.expirationTime)) {
m.mutex.Lock()
delete(m.data, key)
m.mutex.Unlock()
}
}
m.mutex.Unlock()
}
}()
return m
Expand Down

0 comments on commit b909143

Please sign in to comment.