contenthash: data race

Multiple calls to GetCacheContext may occur from multiple threads;
however they should only occur when dealing with an ImmutableRef.
For this case we still need to perform a lock to prevent data race
warnings; however in reality the linkMap will be unused.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
This commit is contained in:
Alex Couture-Beil
2023-07-10 16:52:38 -07:00
committed by Alex Couture-Beil
parent 86b22f7eb2
commit caa9579cb0

View File

@@ -110,7 +110,9 @@ func (cm *cacheManager) GetCacheContext(ctx context.Context, md cache.RefMetadat
cm.lruMu.Unlock()
if ok {
cm.locker.Unlock(md.ID())
v.(*cacheContext).mu.Lock() // locking is required because multiple ImmutableRefs can reach this code; however none of them use the linkMap.
v.(*cacheContext).linkMap = map[string][][]byte{}
v.(*cacheContext).mu.Unlock()
return v.(*cacheContext), nil
}
cc, err := newCacheContext(md)