Fixing race condition

master
Frederick F. Kautz IV 10 years ago
parent 710e732cf0
commit 3a1386165f
  1. 8
      pkg/storage/drivers/memory/memory.go

@ -501,9 +501,9 @@ func (memory *memoryDriver) expireObjects() {
if memory.shutdown { if memory.shutdown {
return return
} }
if len(memory.objectMetadata) > 0 {
var sleepDuration time.Duration var sleepDuration time.Duration
memory.lock.Lock() memory.lock.Lock()
if len(memory.objectMetadata) > 0 {
if k, _, ok := memory.objects.GetOldest(); ok { if k, _, ok := memory.objects.GetOldest(); ok {
key := k.(string) key := k.(string)
object := memory.objectMetadata[key] object := memory.objectMetadata[key]
@ -513,11 +513,11 @@ func (memory *memoryDriver) expireObjects() {
sleepDuration = memory.expiration - time.Now().Sub(object.lastAccessed) sleepDuration = memory.expiration - time.Now().Sub(object.lastAccessed)
} }
} }
memory.lock.Unlock()
time.Sleep(sleepDuration)
} else { } else {
time.Sleep(memory.expiration) sleepDuration = memory.expiration
} }
memory.lock.Unlock()
time.Sleep(sleepDuration)
} }
} }

Loading…
Cancel
Save