randomPeer: Return if the context is cancelled when waiting for peers. (#15876)

* `randomPeer`: Return if the context is cancelled when waiting for peers.

* `randomPeer`: Refactor to reduce indentation.
This commit is contained in:
Manu NALEPA
2025-10-16 23:13:11 +02:00
committed by GitHub
parent b2d350b988
commit 47764696ce
2 changed files with 15 additions and 11 deletions

View File

@@ -1122,19 +1122,21 @@ func randomPeer(
}
}
slices.Sort(nonRateLimitedPeers)
if len(nonRateLimitedPeers) == 0 {
log.WithFields(logrus.Fields{
"peerCount": peerCount,
"delay": waitPeriod,
}).Debug("Waiting for a peer with enough bandwidth for data column sidecars")
time.Sleep(waitPeriod)
continue
if len(nonRateLimitedPeers) > 0 {
slices.Sort(nonRateLimitedPeers)
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
return nonRateLimitedPeers[randomIndex], nil
}
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
return nonRateLimitedPeers[randomIndex], nil
log.WithFields(logrus.Fields{
"peerCount": peerCount,
"delay": waitPeriod,
}).Debug("Waiting for a peer with enough bandwidth for data column sidecars")
select {
case <-time.After(waitPeriod):
case <-ctx.Done():
}
}
return "", ctx.Err()

View File

@@ -0,0 +1,2 @@
### Fixed
- `randomPeer`: Return if the context is cancelled when waiting for peers.