Browse code

Do not panic on redundant UpdateAttachment

Signed-off-by: Alessandro Boch <aboch@docker.com>

Alessandro Boch authored on 2017/03/24 22:43:23
Showing 2 changed files
... ...
@@ -126,6 +126,7 @@ type Cluster struct {
126 126
 type attacher struct {
127 127
 	taskID           string
128 128
 	config           *network.NetworkingConfig
129
+	inProgress       bool
129 130
 	attachWaitCh     chan *network.NetworkingConfig
130 131
 	attachCompleteCh chan struct{}
131 132
 	detachWaitCh     chan struct{}
... ...
@@ -81,15 +81,22 @@ func attacherKey(target, containerID string) string {
81 81
 // waiter who is trying to start or attach the container to the
82 82
 // network.
83 83
 func (c *Cluster) UpdateAttachment(target, containerID string, config *network.NetworkingConfig) error {
84
-	c.mu.RLock()
84
+	c.mu.Lock()
85 85
 	attacher, ok := c.attachers[attacherKey(target, containerID)]
86
-	c.mu.RUnlock()
87 86
 	if !ok || attacher == nil {
87
+		c.mu.Unlock()
88 88
 		return fmt.Errorf("could not find attacher for container %s to network %s", containerID, target)
89 89
 	}
90
+	if attacher.inProgress {
91
+		logrus.Debugf("Discarding redundant notice of resource allocation on network %s for task id %s", target, attacher.taskID)
92
+		c.mu.Unlock()
93
+		return nil
94
+	}
95
+	attacher.inProgress = true
96
+	c.mu.Unlock()
90 97
 
91 98
 	attacher.attachWaitCh <- config
92
-	close(attacher.attachWaitCh)
99
+
93 100
 	return nil
94 101
 }
95 102