Skip to content

Commit 0bc9f7b

Browse files
committed
Avoid using canceled context in unpacker cleanup
Signed-off-by: Derek McGowan <[email protected]>
1 parent 341a494 commit 0bc9f7b

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/unpack/unpacker.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (u *Unpacker) unpack(
342342
}
343343

344344
// Abort the snapshot if commit does not happen
345-
abort := func() {
345+
abort := func(ctx context.Context) {
346346
if err := sn.Remove(ctx, key); err != nil {
347347
log.G(ctx).WithError(err).Errorf("failed to cleanup %q", key)
348348
}
@@ -367,28 +367,28 @@ func (u *Unpacker) unpack(
367367

368368
select {
369369
case <-ctx.Done():
370-
abort()
370+
abort(context.Background()) // Cleanup context
371371
return ctx.Err()
372372
case err := <-fetchErr:
373373
if err != nil {
374-
abort()
374+
abort(ctx)
375375
return err
376376
}
377377
case <-fetchC[i-fetchOffset]:
378378
}
379379

380380
diff, err := a.Apply(ctx, desc, mounts, unpack.ApplyOpts...)
381381
if err != nil {
382-
abort()
382+
abort(ctx)
383383
return fmt.Errorf("failed to extract layer %s: %w", diffIDs[i], err)
384384
}
385385
if diff.Digest != diffIDs[i] {
386-
abort()
386+
abort(ctx)
387387
return fmt.Errorf("wrong diff id calculated on extraction %q", diffIDs[i])
388388
}
389389

390390
if err = sn.Commit(ctx, chainID, key, opts...); err != nil {
391-
abort()
391+
abort(ctx)
392392
if errdefs.IsAlreadyExists(err) {
393393
return nil
394394
}

0 commit comments

Comments
 (0)