From 907efa17aac7e9e2400e2dc03a3a61125374f48f Mon Sep 17 00:00:00 2001 From: Larry <92799281+brilliant-lx@users.noreply.github.com> Date: Sun, 16 Apr 2023 15:36:52 +0800 Subject: [PATCH] fix: panic on using WaitGroup after it is freed (#1464) --- core/blockchain.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index b7838a7719..2e67c2f3c1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1546,18 +1546,20 @@ 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) break } - wg.Add(1) + wg2.Add(1) go func() { triedb.Dereference(root.(common.Hash)) - wg.Done() + wg2.Done() }() } + wg2.Wait() } } return nil