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