fix(host): avoid deadlock when fetch image fails

This commit is contained in:
rainzm
2022-03-10 18:36:27 +08:00
parent 0bb5d074e4
commit ea47164a4d
+7 -2
View File
@@ -188,6 +188,13 @@ func (l *SLocalImageCache) prepare(ctx context.Context, input api.CacheImageInpu
}
func (l *SLocalImageCache) fetch(ctx context.Context, input api.CacheImageInput, callback func(progress, progressMbps float64, totalSizeMb int64)) error {
// Whether successful or not, fetch should reset the condition variable and wakes up other waiters
defer func() {
l.cond.L.Lock()
l.remoteFile = nil
l.cond.Broadcast()
l.cond.L.Unlock()
}()
var _fetch = func() error {
if len(l.Manager.GetId()) > 0 {
_, err := hostutils.RemoteStoragecacheCacheImage(ctx,
@@ -207,10 +214,8 @@ func (l *SLocalImageCache) fetch(ctx context.Context, input api.CacheImageInput,
l.Size = l.GetSize() / 1024 / 1024
l.Desc.Id = l.imageId
l.remoteFile = nil
l.lastCheckTime = time.Now()
l.consumerCount++
l.cond.Broadcast()
bDesc, err := json.Marshal(l.Desc)
if err != nil {