Skip to content

Commit

Permalink
fix: avoid hashing under a lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed May 24, 2019
1 parent 80d3b47 commit a3a726c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ func (rt *RoutingTable) Update(p peer.ID) (evicted peer.ID, err error) {
// Remove deletes a peer from the routing table. This is to be used
// when we are sure a node has disconnected completely.
func (rt *RoutingTable) Remove(p peer.ID) {
rt.tabLock.Lock()
defer rt.tabLock.Unlock()
peerID := ConvertPeerID(p)
cpl := CommonPrefixLen(peerID, rt.local)

rt.tabLock.Lock()
defer rt.tabLock.Unlock()

bucketID := cpl
if bucketID >= len(rt.Buckets) {
bucketID = len(rt.Buckets) - 1
Expand Down

0 comments on commit a3a726c

Please sign in to comment.