Преглед на файлове

Merge pull request #32085 from aboch/bd

Do not panic on redundant UpdateAttachment
Sebastiaan van Stijn преди 8 години
родител
ревизия
a1099010b0
променени са 2 файла, в които са добавени 11 реда и са изтрити 3 реда
  1. 1 0
      daemon/cluster/cluster.go
  2. 10 3
      daemon/cluster/networks.go

+ 1 - 0
daemon/cluster/cluster.go

@@ -126,6 +126,7 @@ type Cluster struct {
 type attacher struct {
 	taskID           string
 	config           *network.NetworkingConfig
+	inProgress       bool
 	attachWaitCh     chan *network.NetworkingConfig
 	attachCompleteCh chan struct{}
 	detachWaitCh     chan struct{}

+ 10 - 3
daemon/cluster/networks.go

@@ -81,15 +81,22 @@ func attacherKey(target, containerID string) string {
 // waiter who is trying to start or attach the container to the
 // network.
 func (c *Cluster) UpdateAttachment(target, containerID string, config *network.NetworkingConfig) error {
-	c.mu.RLock()
+	c.mu.Lock()
 	attacher, ok := c.attachers[attacherKey(target, containerID)]
-	c.mu.RUnlock()
 	if !ok || attacher == nil {
+		c.mu.Unlock()
 		return fmt.Errorf("could not find attacher for container %s to network %s", containerID, target)
 	}
+	if attacher.inProgress {
+		logrus.Debugf("Discarding redundant notice of resource allocation on network %s for task id %s", target, attacher.taskID)
+		c.mu.Unlock()
+		return nil
+	}
+	attacher.inProgress = true
+	c.mu.Unlock()
 
 	attacher.attachWaitCh <- config
-	close(attacher.attachWaitCh)
+
 	return nil
 }