Ver código fonte

Merge pull request #1209 from mrjana/networkdb

Fix couple of panics in networkdb
Santhosh Manohar 9 anos atrás
pai
commit
87dad85768
2 arquivos alterados com 17 adições e 2 exclusões
  1. 12 2
      libnetwork/networkdb/cluster.go
  2. 5 0
      libnetwork/networkdb/delegate.go

+ 12 - 2
libnetwork/networkdb/cluster.go

@@ -184,7 +184,8 @@ func (nDB *NetworkDB) reapTableEntries() {
 func (nDB *NetworkDB) gossip() {
 	networkNodes := make(map[string][]string)
 	nDB.RLock()
-	for nid := range nDB.networks[nDB.config.NodeName] {
+	thisNodeNetworks := nDB.networks[nDB.config.NodeName]
+	for nid := range thisNodeNetworks {
 		networkNodes[nid] = nDB.networkNodes[nid]
 
 	}
@@ -195,8 +196,17 @@ func (nDB *NetworkDB) gossip() {
 		bytesAvail := udpSendBuf - compoundHeaderOverhead
 
 		nDB.RLock()
-		broadcastQ := nDB.networks[nDB.config.NodeName][nid].tableBroadcasts
+		network, ok := thisNodeNetworks[nid]
 		nDB.RUnlock()
+		if !ok || network == nil {
+			// It is normal for the network to be removed
+			// between the time we collect the network
+			// attachments of this node and processing
+			// them here.
+			continue
+		}
+
+		broadcastQ := network.tableBroadcasts
 
 		if broadcastQ == nil {
 			logrus.Errorf("Invalid broadcastQ encountered while gossiping for network %s", nid)

+ 5 - 0
libnetwork/networkdb/delegate.go

@@ -146,6 +146,11 @@ func (nDB *NetworkDB) handleTableMessage(buf []byte) {
 		}
 
 		broadcastQ := n.tableBroadcasts
+
+		if broadcastQ == nil {
+			return
+		}
+
 		broadcastQ.QueueBroadcast(&tableEventMessage{
 			msg:   buf,
 			id:    tEvent.NetworkID,