Merge pull request #771 from milosgajdos83/peers-race

Remove data race; Unlock once done pruning/deleting
This commit is contained in:
Asim Aslam 2019-09-19 11:59:03 +01:00 committed by GitHub
commit 0abeb3f660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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