Browse Source

Merge pull request #2180 from ctelfer/fix-overlay-deadlock-regression

Fix spurious deadlock in overlay driver
Flavio Crisciani 7 years ago
parent
commit
5f23795eef
1 changed files with 10 additions and 2 deletions
  1. 10 2
      libnetwork/drivers/overlay/ov_network.go

+ 10 - 2
libnetwork/drivers/overlay/ov_network.go

@@ -244,7 +244,15 @@ func (d *driver) DeleteNetwork(nid string) error {
 	}
 	}
 
 
 	d.Lock()
 	d.Lock()
-	defer d.Unlock()
+	// Only perform a peer flush operation (if required) AFTER unlocking
+	// the driver lock to avoid deadlocking w/ the peerDB.
+	var doPeerFlush bool
+	defer func() {
+		d.Unlock()
+		if doPeerFlush {
+			d.peerFlush(nid)
+		}
+	}()
 
 
 	// This is similar to d.network(), but we need to keep holding the lock
 	// This is similar to d.network(), but we need to keep holding the lock
 	// until we are done removing this network.
 	// until we are done removing this network.
@@ -270,7 +278,7 @@ func (d *driver) DeleteNetwork(nid string) error {
 		}
 		}
 	}
 	}
 	// flush the peerDB entries
 	// flush the peerDB entries
-	d.peerFlush(nid)
+	doPeerFlush = true
 	delete(d.networks, nid)
 	delete(d.networks, nid)
 
 
 	vnis, err := n.releaseVxlanID()
 	vnis, err := n.releaseVxlanID()