Lock the Nodes method properly when collecting them.

This commit is contained in:
Milos Gajdos
2019-09-10 13:31:02 +01:00
parent 4c709f7ac1
commit cbce5490d7
3 changed files with 30 additions and 20 deletions

View File

@@ -46,16 +46,16 @@ func (n *node) Network() Network {
// Nodes returns a slice if all nodes in node topology
func (n *node) Nodes() []Node {
//track the visited nodes
visited := make(map[string]*node)
// queue of the nodes to visit
queue := list.New()
// we need to freeze the network graph here
// otherwise we might get invalid results
n.RLock()
defer n.RUnlock()
//track the visited nodes
visited := make(map[string]*node)
// queue of the nodes to visit
queue := list.New()
// push node to the back of queue
queue.PushBack(n)
// mark the node as visited