From 2b0f56898d233cefee3b17e8ad61529660f5cd92 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 43d899d77e..c67ceb2097 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1584,18 +1584,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