Fix a potential race between ExpireObjects() and Set() over items map

This commit is contained in:
Harshavardhana 2015-05-04 22:36:43 -07:00
parent 3fc9b4554f
commit 193a6606db
1 changed files with 3 additions and 2 deletions

View File

@ -89,13 +89,14 @@ func (r *Intelligent) ExpireObjects(gcInterval time.Duration) {
r.gcInterval = gcInterval r.gcInterval = gcInterval
go func() { go func() {
for range time.Tick(gcInterval) { for range time.Tick(gcInterval) {
for key := range r.items {
r.Lock() r.Lock()
for key := range r.items {
if !r.isValid(key) { if !r.isValid(key) {
r.Delete(key) r.Delete(key)
} }
r.Unlock()
} }
r.Unlock()
} }
}() }()
} }