Remove data race; Unlock once done pruning/deleting

This commit is contained in:
Milos Gajdos 2019-09-19 11:53:13 +01:00
parent ee74e26582
commit a38482ffcb
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -30,8 +30,6 @@ type node struct {
address string
// peers are nodes with direct link to this node
peers map[string]*node
// edges store the node edges
edges map[string]map[string]*node
// network returns the node network
network Network
// lastSeen keeps track of node lifetime and updates
@ -196,7 +194,7 @@ func (n *node) GetPeerNode(id string) *node {
// DeletePeerNode removes peer node from node topology
func (n *node) DeletePeerNode(id string) error {
n.Lock()
n.Unlock()
defer n.Unlock()
untilNoMorePeers := func(node *node) bool {
return node == nil
@ -223,7 +221,7 @@ func (n *node) DeletePeerNode(id string) error {
// It returns a map of the the nodes that got pruned
func (n *node) PruneStalePeerNodes(pruneTime time.Duration) map[string]*node {
n.Lock()
n.Unlock()
defer n.Unlock()
untilNoMorePeers := func(node *node) bool {
return node == nil