Skip to content

Commit

Permalink
fix: panic on using WaitGroup after it is freed
Browse files Browse the repository at this point in the history
  • Loading branch information
brilliant-lx committed Apr 14, 2023
1 parent e4b6ab9 commit b4721f4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// If we're running an archive node, always flush
if bc.cacheConfig.TrieDirtyDisabled {
err := triedb.Commit(block.Root(), false, nil)
wg.Done()
if err != nil {
return err
}
Expand Down Expand Up @@ -1584,18 +1585,21 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
}
}
// Garbage collect anything below our required write retention
wg2 := sync.WaitGroup{}
for !bc.triegc.Empty() {
root, number := bc.triegc.Pop()
if uint64(-number) > chosen {
bc.triegc.Push(root, number)
wg.Done()
break
}
wg.Add(1)
wg2.Add(1)
go func() {
triedb.Dereference(root.(common.Hash))
wg.Done()
wg2.Done()
}()
}
wg2.Wait()
}
}
return nil
Expand Down

0 comments on commit b4721f4

Please sign in to comment.