Skip to content

Commit ff0bac6

Browse files
JulianVenturaJulian Ventura
andauthored
fix(aggregator): add garbage collector mutex (#1430)
Co-authored-by: Julian Ventura <[email protected]>
1 parent a26526c commit ff0bac6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

aggregator/pkg/aggregator.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ type Aggregator struct {
7474
// Note: In case of a reboot it can start from 0 again
7575
nextBatchIndex uint32
7676

77-
// Mutex to protect batchesIdentifierHashByIdx, batchesIdxByIdentifierHash and nextBatchIndex
77+
// Mutex to protect:
78+
// - batchesIdentifierHashByIdx
79+
// - batchesIdxByIdentifierHash
80+
// - batchCreatedBlockByIdx
81+
// - batchDataByIdentifierHash
82+
// - nextBatchIndex
7883
taskMutex *sync.Mutex
7984

8085
// Mutex to protect ethereum wallet
@@ -443,6 +448,8 @@ func (agg *Aggregator) ClearTasksFromMaps() {
443448
agg.logger.Warn("No old tasks found")
444449
continue // Retry in the next iteration
445450
}
451+
agg.taskMutex.Lock()
452+
agg.AggregatorConfig.BaseConfig.Logger.Info("- Locked Resources: Cleaning finalized tasks")
446453

447454
taskIdxToDelete := agg.batchesIdxByIdentifierHash[*oldTaskIdHash]
448455
agg.logger.Info("Old task found", "taskIndex", taskIdxToDelete)
@@ -460,6 +467,8 @@ func (agg *Aggregator) ClearTasksFromMaps() {
460467
}
461468
}
462469
lastIdxDeleted = taskIdxToDelete
470+
agg.taskMutex.Unlock()
471+
agg.AggregatorConfig.BaseConfig.Logger.Info("- Unlocked Resources: Cleaning finalized tasks")
463472
agg.AggregatorConfig.BaseConfig.Logger.Info("Done cleaning finalized tasks from maps")
464473
}
465474
}

0 commit comments

Comments
 (0)