Browse code

plugin: withFetchProgress work around "nested context in loop (fatcontext)"

This needs a better solution, but this allows enabling the "fatcontext"
linter.

plugin/fetch_linux.go:250:6: nested context in loop (fatcontext)
ctx = context.Background()
^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/02/08 07:11:14
Showing 1 changed files
... ...
@@ -237,7 +237,13 @@ func withFetchProgress(cs content.Store, out progress.Output, ref reference.Name
237 237
 			defer timer.Stop()
238 238
 
239 239
 			var pulling bool
240
-			var ctxErr error
240
+			var (
241
+				// make sure we can still fetch from the content store
242
+				// if the main context is cancelled
243
+				// TODO: Might need to add some sort of timeout; see https://github.com/moby/moby/issues/49413
244
+				ctxErr      error
245
+				noCancelCTX = context.WithoutCancel(ctx)
246
+			)
241 247
 
242 248
 			for {
243 249
 				timer.Reset(100 * time.Millisecond)
... ...
@@ -245,21 +251,18 @@ func withFetchProgress(cs content.Store, out progress.Output, ref reference.Name
245 245
 				select {
246 246
 				case <-ctx.Done():
247 247
 					ctxErr = ctx.Err()
248
-					// make sure we can still fetch from the content store
249
-					// TODO: Might need to add some sort of timeout
250
-					ctx = context.Background()
251 248
 				case <-timer.C:
252 249
 				}
253 250
 
254
-				s, err := cs.Status(ctx, key)
251
+				s, err := cs.Status(noCancelCTX, key)
255 252
 				if err != nil {
256 253
 					if !cerrdefs.IsNotFound(err) {
257
-						log.G(ctx).WithError(err).WithField("layerDigest", desc.Digest.String()).Error("Error looking up status of plugin layer pull")
254
+						log.G(noCancelCTX).WithError(err).WithField("layerDigest", desc.Digest.String()).Error("Error looking up status of plugin layer pull")
258 255
 						progress.Update(out, id, err.Error())
259 256
 						return
260 257
 					}
261 258
 
262
-					if _, err := cs.Info(ctx, desc.Digest); err == nil {
259
+					if _, err := cs.Info(noCancelCTX, desc.Digest); err == nil {
263 260
 						progress.Update(out, id, "Download complete")
264 261
 						return
265 262
 					}