浏览代码

Merge pull request #629 from sanimej/slice

Fix the overlay cleanup in the multi-subnet case
Jana Radhakrishnan 9 年之前
父节点
当前提交
fb19b4f488
共有 2 个文件被更改,包括 10 次插入18 次删除
  1. 4 0
      libnetwork/drivers/overlay/joinleave.go
  2. 6 18
      libnetwork/drivers/overlay/ov_network.go

+ 4 - 0
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()

+ 6 - 18
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() {