cache: fix possible prune deadlock

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-08-31 11:59:53 -07:00
parent 2759005f6a
commit 28fec2b9cb
1 changed files with 3 additions and 3 deletions

6
cache/manager.go vendored
View File

@ -360,10 +360,10 @@ func (cm *cacheManager) prune(ctx context.Context, ch chan client.UsageInfo, opt
gcMode := opt.keepBytes != 0
cutOff := time.Now().Add(-opt.keepDuration)
locked := map[*cacheRecord]struct{}{}
locked := map[*sync.Mutex]struct{}{}
for _, cr := range cm.records {
if _, ok := locked[cr]; ok {
if _, ok := locked[cr.mu]; ok {
continue
}
cr.mu.Lock()
@ -431,7 +431,7 @@ func (cm *cacheManager) prune(ctx context.Context, ch chan client.UsageInfo, opt
return err
}
} else {
locked[cr] = struct{}{}
locked[cr.mu] = struct{}{}
continue // leave the record locked
}
}