Skip to content

Commit d99c6b8

Browse files
committed
swarm/controller: allow cancellation to propagate
Ensure that cancellation of a pull propagates rather than continuing to container creation. This ensures that the `Prepare` method is properly re-entrant. Signed-off-by: Stephen J Day <[email protected]>
1 parent 8c7468b commit d99c6b8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

daemon/cluster/executor/container/controller.go

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func (r *controller) Prepare(ctx context.Context) error {
8787

8888
if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" {
8989
if err := r.adapter.pullImage(ctx); err != nil {
90+
cause := errors.Cause(err)
91+
if cause == context.Canceled || cause == context.DeadlineExceeded {
92+
return err
93+
}
94+
9095
// NOTE(stevvooe): We always try to pull the image to make sure we have
9196
// the most up to date version. This will return an error, but we only
9297
// log it. If the image truly doesn't exist, the create below will

distribution/errors.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ type fallbackError struct {
4040

4141
// Error renders the FallbackError as a string.
4242
func (f fallbackError) Error() string {
43-
return f.err.Error()
43+
return f.Cause().Error()
44+
}
45+
46+
func (f fallbackError) Cause() error {
47+
return f.err
4448
}
4549

4650
// shouldV2Fallback returns true if this error is a reason to fall back to v1.

0 commit comments

Comments
 (0)