fix invalid cancellation errors on pull

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-11-30 21:56:57 -08:00
parent e531c59882
commit e46cfab9fb
4 changed files with 24 additions and 16 deletions

View File

@ -941,11 +941,6 @@ func testClientSlowCacheRootfsRef(t *testing.T, sb integration.Sandbox) {
ctx := context.TODO()
// https://github.com/moby/buildkit/issues/1820
if sb.ContainerdAddress() != "" {
t.Skip()
}
c, err := New(ctx, sb.Address())
require.NoError(t, err)
defer c.Close()

View File

@ -255,7 +255,7 @@ func (gf *gatewayFrontend) Solve(ctx context.Context, llbBridge frontend.Fronten
err = w.Executor().Run(ctx, "", mountWithSession(rootFS, session.NewGroup(sid)), nil, executor.ProcessInfo{Meta: meta, Stdin: lbf.Stdin, Stdout: lbf.Stdout, Stderr: os.Stderr}, nil)
if err != nil {
if errors.Is(err, context.Canceled) && lbf.isErrServerClosed {
if errdefs.IsCanceled(err) && lbf.isErrServerClosed {
err = errors.Errorf("frontend grpc server closed unexpectedly")
}
// An existing error (set via Return rpc) takes

13
solver/errdefs/context.go Normal file
View File

@ -0,0 +1,13 @@
package errdefs
import (
"context"
"errors"
"github.com/moby/buildkit/util/grpcerrors"
"google.golang.org/grpc/codes"
)
func IsCanceled(err error) bool {
return errors.Is(err, context.Canceled) || grpcerrors.Code(err) == codes.Canceled
}

View File

@ -10,18 +10,19 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/diff"
containerderrdefs "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
ctdlabels "github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/snapshots"
"github.com/docker/docker/errdefs"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/snapshot"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/source"
"github.com/moby/buildkit/util/flightcontrol"
"github.com/moby/buildkit/util/imageutil"
@ -177,7 +178,7 @@ func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (cach
return nil, p.cacheKeyErr
}
defer func() {
if !errors.Is(err, context.Canceled) {
if !errdefs.IsCanceled(err) {
p.cacheKeyErr = err
}
}()
@ -186,12 +187,7 @@ func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (cach
return nil, err
}
p.releaseTmpLeases = done
imageutil.AddLease(p.releaseTmpLeases)
defer func() {
if err != nil {
p.releaseTmpLeases(ctx)
}
}()
defer imageutil.AddLease(done)
resolveProgressDone := oneOffProgress(ctx, "resolve "+p.Src.String())
defer func() {
@ -283,7 +279,11 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (ir cache.Immuta
if len(p.manifest.Descriptors) == 0 {
return nil, nil
}
defer p.releaseTmpLeases(ctx)
defer func() {
if p.releaseTmpLeases != nil {
p.releaseTmpLeases(context.TODO())
}
}()
var current cache.ImmutableRef
defer func() {
@ -306,7 +306,7 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (ir cache.Immuta
}
for _, desc := range p.manifest.Nonlayers {
if _, err := p.ContentStore.Info(ctx, desc.Digest); errdefs.IsNotFound(err) {
if _, err := p.ContentStore.Info(ctx, desc.Digest); containerderrdefs.IsNotFound(err) {
// manifest or config must have gotten gc'd after CacheKey, re-pull them
ctx, done, err := leaseutil.WithLease(ctx, p.LeaseManager, leaseutil.MakeTemporary)
if err != nil {