From ae10617349ec0ab8aeacb45004a40d6af3bce980 Mon Sep 17 00:00:00 2001 From: Lazar Date: Thu, 19 Dec 2024 12:47:37 +0100 Subject: [PATCH] fix double close --- .../stakingeventwatcher/stakingeventwatcher.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go index f6b9ecb..ed0f927 100644 --- a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go +++ b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go @@ -676,7 +676,8 @@ func (sew *StakingEventWatcher) activateBtcDelegation( requiredDepth uint32, done chan struct{}, ) { - defer close(done) + var once sync.Once + defer once.Do(func() { close(done) }) sew.metrics.NumberOfActivationInProgress.Inc() defer sew.metrics.NumberOfActivationInProgress.Dec() @@ -714,7 +715,9 @@ func (sew *StakingEventWatcher) activateBtcDelegation( sew.metrics.ReportedActivateDelegationsCounter.Inc() - close(done) + once.Do(func() { + close(done) + }) sew.pendingTracker.RemoveDelegation(stakingTxHash) sew.metrics.NumberOfVerifiedDelegations.Dec()