Skip to content

Commit

Permalink
fix concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM committed Aug 13, 2024
1 parent 07510f3 commit 783e3b6
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,21 @@ func New(
func (a *Aggregator) retrieveWitnesses() {
currentWorkers := 0
for {
select {
case <-a.ctx.Done():
return
case dbBatch := <-a.witnessRetrievalChan:
a.activeWitnessRetrievalWorkersMutex.Lock()
currentWorkers = a.activeWitnessRetrievalWorkers
a.activeWitnessRetrievalWorkersMutex.Unlock()
dbBatch := <-a.witnessRetrievalChan
a.activeWitnessRetrievalWorkersMutex.Lock()
currentWorkers = a.activeWitnessRetrievalWorkers
a.activeWitnessRetrievalWorkersMutex.Unlock()

for currentWorkers >= a.cfg.MaxWitnessRetrievalWorkers {
time.Sleep(a.cfg.RetryTime.Duration)
a.activeWitnessRetrievalWorkersMutex.Lock()
currentWorkers = a.activeWitnessRetrievalWorkers
a.activeWitnessRetrievalWorkersMutex.Unlock()
}
for currentWorkers >= a.cfg.MaxWitnessRetrievalWorkers {
time.Sleep(a.cfg.RetryTime.Duration)
a.activeWitnessRetrievalWorkersMutex.Lock()
a.activeWitnessRetrievalWorkers++
currentWorkers = a.activeWitnessRetrievalWorkers
a.activeWitnessRetrievalWorkersMutex.Unlock()
go a.retrieveWitness(dbBatch)
}
a.activeWitnessRetrievalWorkersMutex.Lock()
a.activeWitnessRetrievalWorkers++
a.activeWitnessRetrievalWorkersMutex.Unlock()
go a.retrieveWitness(dbBatch)
}
}

Expand Down

0 comments on commit 783e3b6

Please sign in to comment.