@@ -146,6 +146,15 @@ func StartDockerImageDownload(ctx context.Context, image string) bool {
146146
147147 // Start the download in a goroutine with retry logic
148148 go func () {
149+ defer func () {
150+ pullState .mu .Lock ()
151+ delete (pullState .downloading , image )
152+ pullState .mu .Unlock ()
153+ if r := recover (); r != nil {
154+ dockerImagesLog .Printf ("Panic in docker image download for %s (recovered): %v" , image , r )
155+ }
156+ }()
157+
149158 dockerImagesLog .Printf ("Starting download of image %s" , image )
150159
151160 // Retry configuration
@@ -159,9 +168,6 @@ func StartDockerImageDownload(ctx context.Context, image string) bool {
159168 // Check if context was cancelled
160169 if ctx .Err () != nil {
161170 dockerImagesLog .Printf ("Download of image %s cancelled: %v" , image , ctx .Err ())
162- pullState .mu .Lock ()
163- delete (pullState .downloading , image )
164- pullState .mu .Unlock ()
165171 return
166172 }
167173
@@ -173,9 +179,6 @@ func StartDockerImageDownload(ctx context.Context, image string) bool {
173179 if err == nil {
174180 // Success
175181 dockerImagesLog .Printf ("Successfully downloaded image %s" , image )
176- pullState .mu .Lock ()
177- delete (pullState .downloading , image )
178- pullState .mu .Unlock ()
179182 return
180183 }
181184
@@ -193,9 +196,6 @@ func StartDockerImageDownload(ctx context.Context, image string) bool {
193196 case <- ctx .Done ():
194197 // Context cancelled during sleep
195198 dockerImagesLog .Printf ("Download of image %s cancelled during retry wait: %v" , image , ctx .Err ())
196- pullState .mu .Lock ()
197- delete (pullState .downloading , image )
198- pullState .mu .Unlock ()
199199 return
200200 }
201201
@@ -205,10 +205,6 @@ func StartDockerImageDownload(ctx context.Context, image string) bool {
205205
206206 // All attempts failed
207207 dockerImagesLog .Printf ("Failed to download image %s after %d attempts: %v\n Output: %s" , image , maxAttempts , lastErr , string (lastOutput ))
208-
209- pullState .mu .Lock ()
210- delete (pullState .downloading , image )
211- pullState .mu .Unlock ()
212208 }()
213209
214210 return true
0 commit comments