From 28fec2b9cb2641cdc668e1fb93f4a205842ffb0c Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 31 Aug 2018 11:59:53 -0700 Subject: [PATCH] cache: fix possible prune deadlock Signed-off-by: Tonis Tiigi --- cache/manager.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cache/manager.go b/cache/manager.go index a6a3f86e..6bfb8abc 100644 --- a/cache/manager.go +++ b/cache/manager.go @@ -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 } }