diff --git a/internal/bloblru/cache.go b/internal/bloblru/cache.go index 1ff52094b..161f15375 100644 --- a/internal/bloblru/cache.go +++ b/internal/bloblru/cache.go @@ -100,7 +100,13 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by waitForResult, isDownloading := c.inProgress[id] if !isDownloading { c.inProgress[id] = finish + } + c.mu.Unlock() + if isDownloading { + // wait for result of parallel download + <-waitForResult + } else { // remove progress channel once finished here defer func() { c.mu.Lock() @@ -109,12 +115,6 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by close(finish) }() } - c.mu.Unlock() - - if isDownloading { - // wait for result of parallel download - <-waitForResult - } // try again. This is necessary independent of whether isDownloading is true or not. // The calls to `c.Get()` and checking/adding the entry in `c.inProgress` are not atomic,