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 <stephen.day@docker.com>
... | ... |
@@ -87,6 +87,11 @@ func (r *controller) Prepare(ctx context.Context) error { |
87 | 87 |
|
88 | 88 |
if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" { |
89 | 89 |
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 |
+ |
|
90 | 95 |
// NOTE(stevvooe): We always try to pull the image to make sure we have |
91 | 96 |
// the most up to date version. This will return an error, but we only |
92 | 97 |
// log it. If the image truly doesn't exist, the create below will |
... | ... |
@@ -40,7 +40,11 @@ type fallbackError struct { |
40 | 40 |
|
41 | 41 |
// Error renders the FallbackError as a string. |
42 | 42 |
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 |
|
44 | 48 |
} |
45 | 49 |
|
46 | 50 |
// shouldV2Fallback returns true if this error is a reason to fall back to v1. |