From a3a726cbe532104f53c1df020fcaf63e75f7e39a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 23 May 2019 22:35:16 -0700 Subject: [PATCH] fix: avoid hashing under a lock --- table.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/table.go b/table.go index b62c6a2..afb8319 100644 --- a/table.go +++ b/table.go @@ -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