From 3bf164e48df2b640545a64ddfcf274c60c042e39 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 24 Mar 2017 06:43:23 -0700 Subject: [PATCH] Do not panic on redundant UpdateAttachment Signed-off-by: Alessandro Boch --- daemon/cluster/cluster.go | 1 + daemon/cluster/networks.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/daemon/cluster/cluster.go b/daemon/cluster/cluster.go index 5c62453435..fec07dc559 100644 --- a/daemon/cluster/cluster.go +++ b/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{} diff --git a/daemon/cluster/networks.go b/daemon/cluster/networks.go index a87b033f6f..4f91c4c136 100644 --- a/daemon/cluster/networks.go +++ b/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 }