Browse code

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 <stephen.day@docker.com>
(cherry picked from commit d99c6b837ffd18ffe5bce801feb4936bf0edd2aa)
Signed-off-by: Tibor Vass <tibor@docker.com>

Stephen J Day authored on 2016/07/26 06:52:27
Showing 2 changed files
... ...
@@ -85,6 +85,11 @@ func (r *controller) Prepare(ctx context.Context) error {
85 85
 	}
86 86
 
87 87
 	if err := r.adapter.pullImage(ctx); err != nil {
88
+		cause := errors.Cause(err)
89
+		if cause == context.Canceled || cause == context.DeadlineExceeded {
90
+			return err
91
+		}
92
+
88 93
 		// NOTE(stevvooe): We always try to pull the image to make sure we have
89 94
 		// the most up to date version. This will return an error, but we only
90 95
 		// 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.