daemon/c8d: Use non cancellable context in defers

Fixes leases not being released when operation was cancelled.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-10-03 15:26:22 +02:00
parent 591c98cdbe
commit 6f27bef9fc
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A
4 changed files with 8 additions and 4 deletions

View file

@ -20,6 +20,7 @@ import (
"github.com/docker/docker/api/types/backend"
imagetypes "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/internal/compatcontext"
registrypkg "github.com/docker/docker/registry"
// "github.com/docker/docker/api/types/container"
@ -450,7 +451,7 @@ func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent st
return nil, err
}
defer func() {
if err := release(ctx); err != nil {
if err := release(compatcontext.WithoutCancel(ctx)); err != nil {
log.G(ctx).WithError(err).Warn("failed to release lease created for create")
}
}()

View file

@ -22,6 +22,7 @@ import (
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/image"
imagespec "github.com/docker/docker/image/spec/specs-go/v1"
"github.com/docker/docker/internal/compatcontext"
"github.com/docker/docker/pkg/archive"
"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity"
@ -74,7 +75,7 @@ func (i *ImageService) CommitImage(ctx context.Context, cc backend.CommitConfig)
return "", fmt.Errorf("failed to create lease for commit: %w", err)
}
defer func() {
if err := release(ctx); err != nil {
if err := release(compatcontext.WithoutCancel(ctx)); err != nil {
log.G(ctx).WithError(err).Warn("failed to release lease created for commit")
}
}()

View file

@ -21,6 +21,7 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
imagespec "github.com/docker/docker/image/spec/specs-go/v1"
"github.com/docker/docker/internal/compatcontext"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/pools"
"github.com/google/uuid"
@ -49,7 +50,7 @@ func (i *ImageService) ImportImage(ctx context.Context, ref reference.Named, pla
return "", errdefs.System(err)
}
defer func() {
if err := release(ctx); err != nil {
if err := release(compatcontext.WithoutCancel(ctx)); err != nil {
logger.WithError(err).Warn("failed to release lease created for import")
}
}()

View file

@ -22,6 +22,7 @@ import (
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/internal/compatcontext"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/opencontainers/go-digest"
@ -84,7 +85,7 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, m
return err
}
defer func() {
if err := release(leasedCtx); err != nil {
if err := release(compatcontext.WithoutCancel(leasedCtx)); err != nil {
log.G(ctx).WithField("image", targetRef).WithError(err).Warn("failed to release lease created for push")
}
}()