From ea47164a4d50c359ff096930a0bb0eee38c8e6b8 Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 10 Mar 2022 18:36:27 +0800 Subject: [PATCH] fix(host): avoid deadlock when fetch image fails --- pkg/hostman/storageman/imagecache_local.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/hostman/storageman/imagecache_local.go b/pkg/hostman/storageman/imagecache_local.go index 37055ecdd6..cbe5560bdf 100644 --- a/pkg/hostman/storageman/imagecache_local.go +++ b/pkg/hostman/storageman/imagecache_local.go @@ -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 {