fix: infinite loop edge case

This commit is contained in:
Cassandra Heart 2024-01-10 22:42:11 -06:00
parent f48f177a10
commit 916a1514f1
No known key found for this signature in database
GPG Key ID: 6352152859385958

View File

@ -1091,7 +1091,15 @@ func (e *CeremonyDataClockConsensusEngine) collect(
latest = e.previousHead
e.syncingStatus = SyncStatusNotSyncing
}
for {
// With large networks and slow syncing machines, this can lead to an
// infinite loop if the list is refreshing fast enough, so make the size
// of the map the maximum loop case:
e.peerMapMx.Lock()
size := len(e.peerMap)
e.peerMapMx.Unlock()
for i := 0; i < size; i++ {
peerId, maxFrame, err := e.GetMostAheadPeer()
if err != nil {
e.logger.Warn("no peers available, skipping sync")