Skip to content

Commit 7cceeab

Browse files
committed
Fix unsafe map access in snapshotter cache
https://go.dev/doc/faq#atomic_maps Signed-off-by: Kern Walster <[email protected]>
1 parent 34263c0 commit 7cceeab

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

snapshotter/demux/cache/snapshotter_cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func NewSnapshotterCache() *SnapshotterCache {
3737

3838
// Get fetches and caches the snapshotter for a given key.
3939
func (cache *SnapshotterCache) Get(ctx context.Context, key string, fetch SnapshotterProvider) (*proxy.RemoteSnapshotter, error) {
40+
cache.mutex.RLock()
4041
snapshotter, ok := cache.snapshotters[key]
42+
cache.mutex.RUnlock()
4143

4244
if !ok {
4345
cache.mutex.Lock()
@@ -92,6 +94,8 @@ func (cache *SnapshotterCache) Evict(key string) error {
9294
// Close calls Close on all cached remote snapshotters.
9395
func (cache *SnapshotterCache) Close() error {
9496
var compiledErr error
97+
cache.mutex.RLock()
98+
defer cache.mutex.RUnlock()
9599
for _, remoteSnapshotter := range cache.snapshotters {
96100
if err := remoteSnapshotter.Close(); err != nil {
97101
compiledErr = multierror.Append(compiledErr, err)

0 commit comments

Comments
 (0)