cluster: Renew the context after communicating with the registry
| ... | ... |
@@ -122,6 +122,16 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity |
| 122 | 122 |
} else {
|
| 123 | 123 |
logrus.Debugf("creating service using supplied digest reference %s", ctnr.Image)
|
| 124 | 124 |
} |
| 125 |
+ |
|
| 126 |
+ // Replace the context with a fresh one. |
|
| 127 |
+ // If we timed out while communicating with the |
|
| 128 |
+ // registry, then "ctx" will already be expired, which |
|
| 129 |
+ // would cause UpdateService below to fail. Reusing |
|
| 130 |
+ // "ctx" could make it impossible to create a service |
|
| 131 |
+ // if the registry is slow or unresponsive. |
|
| 132 |
+ var cancel func() |
|
| 133 |
+ ctx, cancel = c.getRequestContext() |
|
| 134 |
+ defer cancel() |
|
| 125 | 135 |
} |
| 126 | 136 |
|
| 127 | 137 |
r, err := state.controlClient.CreateService(ctx, &swarmapi.CreateServiceRequest{Spec: &serviceSpec})
|
| ... | ... |
@@ -212,6 +222,16 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ |
| 212 | 212 |
} else {
|
| 213 | 213 |
logrus.Debugf("updating service using supplied digest reference %s", newCtnr.Image)
|
| 214 | 214 |
} |
| 215 |
+ |
|
| 216 |
+ // Replace the context with a fresh one. |
|
| 217 |
+ // If we timed out while communicating with the |
|
| 218 |
+ // registry, then "ctx" will already be expired, which |
|
| 219 |
+ // would cause UpdateService below to fail. Reusing |
|
| 220 |
+ // "ctx" could make it impossible to update a service |
|
| 221 |
+ // if the registry is slow or unresponsive. |
|
| 222 |
+ var cancel func() |
|
| 223 |
+ ctx, cancel = c.getRequestContext() |
|
| 224 |
+ defer cancel() |
|
| 215 | 225 |
} |
| 216 | 226 |
|
| 217 | 227 |
var rollback swarmapi.UpdateServiceRequest_Rollback |