Browse Source

fix infinite loop in addrbook

There are cases where we only have a small number of addresses marked
good ("old"), but the selection mechanism keeps trying to select more of these
addresses, and hence ends up in an infinite loop. Here we fix this to
only try and select such "old" addresses if we have enough of them. Note this
means, if we don't have enough of them, we may return more "new"
addresses than otherwise expected by the newSelectionBias.

This whole GetSelectionWithBias method probably needs to be rewritten,
but this is a quick fix for the issue.
pull/3232/head
Ethan Buchman 5 years ago
committed by Anton Kaliaev
parent
commit
7ce1b74cdf
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      p2p/pex/addrbook.go

+ 5
- 1
p2p/pex/addrbook.go View File

@ -411,8 +411,12 @@ func (a *addrBook) GetSelectionWithBias(biasTowardsNewAddrs int) []*p2p.NetAddre
selectionIndex := 0
ADDRS_LOOP:
for selectionIndex < numAddresses {
// determine whether to pick from an old bucket.
// if there's not enough old addresses to pick from, then we cant pick from old bucket.
pickFromOldBucket := int((float64(selectionIndex)/float64(numAddresses))*100) >= biasTowardsNewAddrs
pickFromOldBucket = (pickFromOldBucket && a.nOld > 0) || a.nNew == 0
pickFromOldBucket = (pickFromOldBucket && a.nOld > 0 && len(oldBucketToAddrsMap) < a.nOld) || a.nNew == 0
bucket := make(map[string]*knownAddress)
// loop until we pick a random non-empty bucket


Loading…
Cancel
Save