Skip to content

Commit

Permalink
alternate implementation of grabbing node.ctx.Done() for algorand#3919
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed May 5, 2022
1 parent 704e0b4 commit 433a2ab
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,16 +784,17 @@ func ensureParticipationDB(genesisDir string, log logging.Logger) (account.Parti
// Reload participation keys from disk periodically
func (node *AlgorandFullNode) checkForParticipationKeys() {
defer node.monitoringRoutinesWaitGroup.Done()
done := node.ctx.Done()
ticker := time.NewTicker(node.config.ParticipationKeysRefreshInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
err := node.loadParticipationKeys()
if err != nil {
node.log.Errorf("Could not refresh participation keys: %v", err)
}
case <-node.ctx.Done():
ticker.Stop()
case <-done:
return
}
}
Expand Down Expand Up @@ -1034,13 +1035,14 @@ var txPoolGuage = metrics.MakeGauge(metrics.MetricName{Name: "algod_tx_pool_coun

func (node *AlgorandFullNode) txPoolGaugeThread() {
defer node.monitoringRoutinesWaitGroup.Done()
done := node.ctx.Done()
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
for true {
select {
case <-ticker.C:
txPoolGuage.Set(float64(node.transactionPool.PendingCount()), nil)
case <-node.ctx.Done():
case <-done:
return
}
}
Expand Down Expand Up @@ -1072,10 +1074,11 @@ func (node *AlgorandFullNode) OnNewBlock(block bookkeeping.Block, delta ledgerco
// It runs in a separate thread so that, during catchup, we
// don't have to delete key for each block we received.
func (node *AlgorandFullNode) oldKeyDeletionThread() {
done := node.ctx.Done()
defer node.monitoringRoutinesWaitGroup.Done()
for {
select {
case <-node.ctx.Done():
case <-done:
return
case <-node.oldKeyDeletionNotify:
}
Expand Down

0 comments on commit 433a2ab

Please sign in to comment.