Browse code

Merge pull request #33117 from aaronlehmann/digest-pin-context-17.03

[17.03.2] cluster: Renew the context after communicating with the registry

Sebastiaan van Stijn authored on 2017/05/10 22:45:27
Showing 2 changed files
... ...
@@ -32,6 +32,7 @@ be found.
32 32
  * Retry failed network allocations less aggressively [docker/swarmkit#2021](https://github.com/docker/swarmkit/pull/2021)
33 33
  * Avoid network allocation for tasks that are no longer running [docker/swarmkit#2017](https://github.com/docker/swarmkit/pull/2017)
34 34
  * Bookkeeping fixes inside network allocator allocator [docker/swarmkit#2019](https://github.com/docker/swarmkit/pull/2019) [docker/swarmkit#2020](https://github.com/docker/swarmkit/pull/2020)
35
+* Avoid timing out service create or update when a registry is slow to respond [#31861](https://github.com/docker/docker/pull/31861)
35 36
 
36 37
 ### Windows
37 38
 
... ...
@@ -1119,6 +1119,16 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity
1119 1119
 		} else {
1120 1120
 			logrus.Debugf("creating service using supplied digest reference %s", ctnr.Image)
1121 1121
 		}
1122
+
1123
+		// Replace the context with a fresh one.
1124
+		// If we timed out while communicating with the
1125
+		// registry, then "ctx" will already be expired, which
1126
+		// would cause UpdateService below to fail. Reusing
1127
+		// "ctx" could make it impossible to create a service
1128
+		// if the registry is slow or unresponsive.
1129
+		var newCancel func()
1130
+		ctx, newCancel = c.getRequestContext()
1131
+		defer newCancel()
1122 1132
 	}
1123 1133
 
1124 1134
 	r, err := c.client.CreateService(ctx, &swarmapi.CreateServiceRequest{Spec: &serviceSpec})
... ...
@@ -1230,6 +1240,16 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
1230 1230
 		} else {
1231 1231
 			logrus.Debugf("updating service using supplied digest reference %s", newCtnr.Image)
1232 1232
 		}
1233
+
1234
+		// Replace the context with a fresh one.
1235
+		// If we timed out while communicating with the
1236
+		// registry, then "ctx" will already be expired, which
1237
+		// would cause UpdateService below to fail. Reusing
1238
+		// "ctx" could make it impossible to create a service
1239
+		// if the registry is slow or unresponsive.
1240
+		var newCancel func()
1241
+		ctx, newCancel = c.getRequestContext()
1242
+		defer newCancel()
1233 1243
 	}
1234 1244
 
1235 1245
 	_, err = c.client.UpdateService(