Skip to content

Commit a9e3b18

Browse files
committed
alternate implementation of grabbing node.ctx.Done() for algorand#3919
1 parent 5d2152e commit a9e3b18

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

node/node.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (status StatusReport) TimeSinceLastRound() time.Duration {
9393

9494
// AlgorandFullNode specifies and implements a full Algorand node.
9595
type AlgorandFullNode struct {
96-
mu deadlock.RWMutex
96+
mu deadlock.Mutex
9797
ctx context.Context
9898
cancelCtx context.CancelFunc
9999
config config.Local
@@ -784,16 +784,17 @@ func ensureParticipationDB(genesisDir string, log logging.Logger) (account.Parti
784784
// Reload participation keys from disk periodically
785785
func (node *AlgorandFullNode) checkForParticipationKeys() {
786786
defer node.monitoringRoutinesWaitGroup.Done()
787+
done := node.ctx.Done()
787788
ticker := time.NewTicker(node.config.ParticipationKeysRefreshInterval)
789+
defer ticker.Stop()
788790
for {
789791
select {
790792
case <-ticker.C:
791793
err := node.loadParticipationKeys()
792794
if err != nil {
793795
node.log.Errorf("Could not refresh participation keys: %v", err)
794796
}
795-
case <-node.ctx.Done():
796-
ticker.Stop()
797+
case <-done:
797798
return
798799
}
799800
}
@@ -1034,12 +1035,10 @@ var txPoolGuage = metrics.MakeGauge(metrics.MetricName{Name: "algod_tx_pool_coun
10341035

10351036
func (node *AlgorandFullNode) txPoolGaugeThread() {
10361037
defer node.monitoringRoutinesWaitGroup.Done()
1038+
done := node.ctx.Done()
10371039
ticker := time.NewTicker(10 * time.Second)
10381040
defer ticker.Stop()
10391041
for true {
1040-
node.mu.RLock()
1041-
done := node.ctx.Done()
1042-
node.mu.RUnlock()
10431042
select {
10441043
case <-ticker.C:
10451044
txPoolGuage.Set(float64(node.transactionPool.PendingCount()), nil)
@@ -1075,11 +1074,9 @@ func (node *AlgorandFullNode) OnNewBlock(block bookkeeping.Block, delta ledgerco
10751074
// It runs in a separate thread so that, during catchup, we
10761075
// don't have to delete key for each block we received.
10771076
func (node *AlgorandFullNode) oldKeyDeletionThread() {
1077+
done := node.ctx.Done()
10781078
defer node.monitoringRoutinesWaitGroup.Done()
10791079
for {
1080-
node.mu.RLock()
1081-
done := node.ctx.Done()
1082-
node.mu.RUnlock()
10831080
select {
10841081
case <-done:
10851082
return

0 commit comments

Comments
 (0)