From 4e7d732cf155a77eb73b6ef24145c7072ab0c01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Ram=C3=ADrez?= Date: Tue, 13 Aug 2024 18:09:09 +0200 Subject: [PATCH] fix concurrency --- aggregator/aggregator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index 36b03ce..d7dcbaf 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -196,12 +196,12 @@ func New( } func (a *Aggregator) retrieveWitnesses() { + currentWorkers := 0 for { select { case <-a.ctx.Done(): return case dbBatch := <-a.witnessRetrievalChan: - currentWorkers := 0 a.activeWitnessRetrievalWorkersMutex.Lock() currentWorkers = a.activeWitnessRetrievalWorkers a.activeWitnessRetrievalWorkersMutex.Unlock() @@ -212,10 +212,10 @@ func (a *Aggregator) retrieveWitnesses() { currentWorkers = a.activeWitnessRetrievalWorkers a.activeWitnessRetrievalWorkersMutex.Unlock() } - go a.retrieveWitness(dbBatch) a.activeWitnessRetrievalWorkersMutex.Lock() a.activeWitnessRetrievalWorkers++ a.activeWitnessRetrievalWorkersMutex.Unlock() + go a.retrieveWitness(dbBatch) } } }