image: Add lock around image cache access
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
c53211eacd
commit
125ec8a7bd
1 changed files with 10 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"net"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/containers/image/copy"
|
||||
"github.com/containers/image/docker/reference"
|
||||
|
@ -63,6 +64,7 @@ type imageService struct {
|
|||
indexConfigs map[string]*indexInfo
|
||||
registries []string
|
||||
imageCache map[string]imageCacheItem
|
||||
imageCacheLock sync.Mutex
|
||||
}
|
||||
|
||||
// sizer knows its size.
|
||||
|
@ -249,16 +251,21 @@ func (svc *imageService) ListImages(systemContext *types.SystemContext, filter s
|
|||
}
|
||||
}
|
||||
// Handle the removals.
|
||||
svc.imageCacheLock.Lock()
|
||||
for _, removedID := range removedIDs {
|
||||
delete(svc.imageCache, removedID)
|
||||
}
|
||||
svc.imageCacheLock.Unlock()
|
||||
}()
|
||||
for _, image := range images {
|
||||
visited[image.ID] = struct{}{}
|
||||
var user string
|
||||
var size *uint64
|
||||
var configDigest digest.Digest
|
||||
if cacheItem, ok := svc.imageCache[image.ID]; ok {
|
||||
svc.imageCacheLock.Lock()
|
||||
cacheItem, ok := svc.imageCache[image.ID]
|
||||
svc.imageCacheLock.Unlock()
|
||||
if ok {
|
||||
user, size, configDigest = cacheItem.user, cacheItem.size, cacheItem.configDigest
|
||||
} else {
|
||||
ref, err := istorage.Transport.ParseStoreReference(svc.store, "@"+image.ID)
|
||||
|
@ -291,7 +298,9 @@ func (svc *imageService) ListImages(systemContext *types.SystemContext, filter s
|
|||
size: size,
|
||||
configDigest: configDigest,
|
||||
}
|
||||
svc.imageCacheLock.Lock()
|
||||
svc.imageCache[image.ID] = cacheItem
|
||||
svc.imageCacheLock.Unlock()
|
||||
}
|
||||
name, tags, digests := sortNamesByType(image.Names)
|
||||
imageDigest, repoDigests := svc.makeRepoDigests(digests, tags, image.ID)
|
||||
|
|
Loading…
Reference in a new issue