From 0bc9f7b5450bf74d3904019aff417fd8439c90a8 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 22 Dec 2022 14:53:23 -0800 Subject: [PATCH] Avoid using canceled context in unpacker cleanup Signed-off-by: Derek McGowan --- pkg/unpack/unpacker.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/unpack/unpacker.go b/pkg/unpack/unpacker.go index c7b664fb3..037777841 100644 --- a/pkg/unpack/unpacker.go +++ b/pkg/unpack/unpacker.go @@ -342,7 +342,7 @@ func (u *Unpacker) unpack( } // Abort the snapshot if commit does not happen - abort := func() { + abort := func(ctx context.Context) { if err := sn.Remove(ctx, key); err != nil { log.G(ctx).WithError(err).Errorf("failed to cleanup %q", key) } @@ -367,11 +367,11 @@ func (u *Unpacker) unpack( select { case <-ctx.Done(): - abort() + abort(context.Background()) // Cleanup context return ctx.Err() case err := <-fetchErr: if err != nil { - abort() + abort(ctx) return err } case <-fetchC[i-fetchOffset]: @@ -379,16 +379,16 @@ func (u *Unpacker) unpack( diff, err := a.Apply(ctx, desc, mounts, unpack.ApplyOpts...) if err != nil { - abort() + abort(ctx) return fmt.Errorf("failed to extract layer %s: %w", diffIDs[i], err) } if diff.Digest != diffIDs[i] { - abort() + abort(ctx) return fmt.Errorf("wrong diff id calculated on extraction %q", diffIDs[i]) } if err = sn.Commit(ctx, chainID, key, opts...); err != nil { - abort() + abort(ctx) if errdefs.IsAlreadyExists(err) { return nil }