Skip to content

Commit

Permalink
fix:add lock when del enr
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Kai <[email protected]>
  • Loading branch information
GrapeBaBa committed Jun 19, 2024
1 parent af02291 commit 9918aba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func (d *DiscV5API) DeleteEnr(nodeId string) (bool, error) {
return false, errors.New("record not in local routing table")
}

d.DiscV5.tab.mutex.Lock()
defer d.DiscV5.tab.mutex.Unlock()
b := d.DiscV5.tab.bucket(n.ID())
d.DiscV5.tab.deleteInBucket(b, n.ID())
return true, nil
Expand Down Expand Up @@ -297,6 +299,8 @@ func (p *PortalProtocolAPI) DeleteEnr(nodeId string) (bool, error) {
return false, nil
}

p.portalProtocol.table.mutex.Lock()
defer p.portalProtocol.table.mutex.Unlock()
b := p.portalProtocol.table.bucket(n.ID())
p.portalProtocol.table.deleteInBucket(b, n.ID())
return true, nil
Expand Down

0 comments on commit 9918aba

Please sign in to comment.