From eacb25db31d7b5c541efa4b2ec7ffdfc1f6860fc Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 11 Oct 2016 15:20:15 -0700 Subject: [PATCH] networkdb: fix race in deleteNetwork There are multiple places which reads from that slice(i.e. bulkSync). Signed-off-by: Alexander Morozov --- networkdb/networkdb.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/networkdb/networkdb.go b/networkdb/networkdb.go index a8c942c9cc..816a07ce71 100644 --- a/networkdb/networkdb.go +++ b/networkdb/networkdb.go @@ -496,14 +496,14 @@ func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) { // this func (nDB *NetworkDB) deleteNetworkNode(nid string, nodeName string) { nodes := nDB.networkNodes[nid] - for i, name := range nodes { + newNodes := make([]string, 0, len(nodes)-1) + for _, name := range nodes { if name == nodeName { - nodes[i] = nodes[len(nodes)-1] - nodes = nodes[:len(nodes)-1] - break + continue } + newNodes = append(newNodes, name) } - nDB.networkNodes[nid] = nodes + nDB.networkNodes[nid] = newNodes } // findCommonnetworks find the networks that both this node and the