From e32eea68d653de447a3ff303662d992b6c403e36 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Fri, 21 Jun 2024 09:42:26 +0800 Subject: [PATCH] blsagg: use defer for unlock --- services/bls_aggregation/blsagg.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/services/bls_aggregation/blsagg.go b/services/bls_aggregation/blsagg.go index fab356f9..5763c795 100644 --- a/services/bls_aggregation/blsagg.go +++ b/services/bls_aggregation/blsagg.go @@ -174,15 +174,12 @@ func (a *BlsAggregatorService) InitializeNewTask( a.logger.Debug("AggregatorService initializing new task", "taskIndex", taskIndex, "taskCreatedBlock", taskCreatedBlock, "quorumNumbers", quorumNumbers, "quorumThresholdPercentages", quorumThresholdPercentages, "timeToExpiry", timeToExpiry) a.taskChansMutex.Lock() - signedTaskRespsC, taskExists := a.signedTaskRespsCs[taskIndex] - if !taskExists { - signedTaskRespsC = make(chan types.SignedTaskResponseDigest) - a.signedTaskRespsCs[taskIndex] = signedTaskRespsC - } - a.taskChansMutex.Unlock() - if taskExists { + defer a.taskChansMutex.Unlock() + if _, taskExists := a.signedTaskRespsCs[taskIndex]; taskExists { return TaskAlreadyInitializedErrorFn(taskIndex) } + signedTaskRespsC := make(chan types.SignedTaskResponseDigest) + a.signedTaskRespsCs[taskIndex] = signedTaskRespsC go a.singleTaskAggregatorGoroutineFunc(taskIndex, taskCreatedBlock, quorumNumbers, quorumThresholdPercentages, timeToExpiry, signedTaskRespsC) return nil