From 0b40559c694fe8077bc3e1c12971344579ccbf97 Mon Sep 17 00:00:00 2001 From: Santhosh Manohar Date: Thu, 1 Oct 2015 19:50:17 -0700 Subject: [PATCH] Fix the overlay cleanup in the multi-subnet case Signed-off-by: Santhosh Manohar --- libnetwork/drivers/overlay/joinleave.go | 4 ++++ libnetwork/drivers/overlay/ov_network.go | 24 ++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libnetwork/drivers/overlay/joinleave.go b/libnetwork/drivers/overlay/joinleave.go index 207e65a90d..1ce123cc51 100644 --- a/libnetwork/drivers/overlay/joinleave.go +++ b/libnetwork/drivers/overlay/joinleave.go @@ -43,6 +43,10 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err) } + // joinSubnetSandbox gets called when an endpoint comes up on a new subnet in the + // overlay network. Hence the Endpoint count should be updated outside joinSubnetSandbox + n.incEndpointCount() + sbox := n.sandbox() name1, name2, err := createVethPair() diff --git a/libnetwork/drivers/overlay/ov_network.go b/libnetwork/drivers/overlay/ov_network.go index c7a82b3d75..d09fd56975 100644 --- a/libnetwork/drivers/overlay/ov_network.go +++ b/libnetwork/drivers/overlay/ov_network.go @@ -118,15 +118,13 @@ func (d *driver) DeleteNetwork(nid string) error { return n.releaseVxlanID() } -func (n *network) joinSandbox() error { +func (n *network) incEndpointCount() { n.Lock() - if n.joinCnt != 0 { - n.joinCnt++ - n.Unlock() - return nil - } - n.Unlock() + defer n.Unlock() + n.joinCnt++ +} +func (n *network) joinSandbox() error { // If there is a race between two go routines here only one will win // the other will wait. n.once.Do(func() { @@ -139,20 +137,10 @@ func (n *network) joinSandbox() error { } func (n *network) joinSubnetSandbox(s *subnet) error { - s.once.Do(func() { s.initErr = n.initSubnetSandbox(s) }) - // Increment joinCnt in all the goroutines only when the one time initSandbox - // was a success. - n.Lock() - if s.initErr == nil { - n.joinCnt++ - } - err := s.initErr - n.Unlock() - - return err + return s.initErr } func (n *network) leaveSandbox() {