Skip to content

Commit

Permalink
fix WaitGroup is reused before previous Wait has returned issue
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed May 6, 2022
1 parent cf83586 commit 2e55641
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,14 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
}
// Need persist and prune diff layer
if bc.db.DiffStore() != nil {
bc.wg.Add(1)
go bc.trustedDiffLayerLoop()
}
bc.wg.Add(1)
go bc.untrustedDiffLayerPruneLoop()
if bc.pipeCommit {
// check current block and rewind invalid one
bc.wg.Add(1)
go bc.rewindInvalidHeaderBlockLoop()
}
return bc, nil
Expand Down Expand Up @@ -2408,7 +2411,10 @@ func (bc *BlockChain) updateFutureBlocks() {

func (bc *BlockChain) rewindInvalidHeaderBlockLoop() {
recheck := time.NewTicker(rewindBadBlockInterval)
defer recheck.Stop()
defer func() {
recheck.Stop()
bc.wg.Done()
}()
for {
select {
case <-recheck.C:
Expand All @@ -2421,10 +2427,9 @@ func (bc *BlockChain) rewindInvalidHeaderBlockLoop() {

func (bc *BlockChain) trustedDiffLayerLoop() {
recheck := time.NewTicker(diffLayerFreezerRecheckInterval)
bc.wg.Add(1)
defer func() {
bc.wg.Done()
recheck.Stop()
bc.wg.Done()
}()
for {
select {
Expand Down Expand Up @@ -2554,10 +2559,9 @@ func (bc *BlockChain) removeDiffLayers(diffHash common.Hash) {

func (bc *BlockChain) untrustedDiffLayerPruneLoop() {
recheck := time.NewTicker(diffLayerPruneRecheckInterval)
bc.wg.Add(1)
defer func() {
bc.wg.Done()
recheck.Stop()
bc.wg.Done()
}()
for {
select {
Expand Down
1 change: 1 addition & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestStateProcessorErrors(t *testing.T) {
MuirGlacierBlock: big.NewInt(0),
MirrorSyncBlock: big.NewInt(0),
BrunoBlock: big.NewInt(0),
EulerBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
Ethash: new(params.EthashConfig),
Expand Down

0 comments on commit 2e55641

Please sign in to comment.