Ver código fonte

Fix possible nil pointer exception

It is possible that the node is not yet present in
the node list map. In this case just print a warning
and return. The next iteration would be fine

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
Flavio Crisciani 6 anos atrás
pai
commit
151f42aeaa
2 arquivos alterados com 9 adições e 6 exclusões
  1. 3 5
      libnetwork/network.go
  2. 6 1
      libnetwork/networkdb/cluster.go

+ 3 - 5
libnetwork/network.go

@@ -396,11 +396,9 @@ func (n *network) validateConfiguration() error {
 					driverOptions map[string]string
 					opts          interface{}
 				)
-				switch data.(type) {
-				case map[string]interface{}:
-					opts = data.(map[string]interface{})
-				case map[string]string:
-					opts = data.(map[string]string)
+				switch t := data.(type) {
+				case map[string]interface{}, map[string]string:
+					opts = t
 				}
 				ba, err := json.Marshal(opts)
 				if err != nil {

+ 6 - 1
libnetwork/networkdb/cluster.go

@@ -288,7 +288,12 @@ func (nDB *NetworkDB) rejoinClusterBootStrap() {
 		return
 	}
 
-	myself, _ := nDB.nodes[nDB.config.NodeID]
+	myself, ok := nDB.nodes[nDB.config.NodeID]
+	if !ok {
+		nDB.RUnlock()
+		logrus.Warnf("rejoinClusterBootstrap unable to find local node info using ID:%v", nDB.config.NodeID)
+		return
+	}
 	bootStrapIPs := make([]string, 0, len(nDB.bootStrapIP))
 	for _, bootIP := range nDB.bootStrapIP {
 		// botostrap IPs are usually IP:port from the Join