From 62d10e6ac6b3f2a5709161c6fb6a9fe6c9f0b2ab Mon Sep 17 00:00:00 2001 From: Keefe-Liu Date: Thu, 28 Oct 2021 16:13:54 +0800 Subject: [PATCH 1/2] fix goroutine leak in prefetcher Signed-off-by: Keefe-Liu --- core/state/statedb.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/state/statedb.go b/core/state/statedb.go index c68e09490c..c7a9d92ef7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -958,6 +958,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) { // goes into transaction receipts. func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { if s.lightProcessed { + s.StopPrefetcher() return s.trie.Hash() } // Finalise all the dirty storage states and write them into the tries From f6e8f582ce0f6c24c4dfe653e9d9500a7aafb3ea Mon Sep 17 00:00:00 2001 From: Keefe-Liu Date: Thu, 28 Oct 2021 16:19:13 +0800 Subject: [PATCH 2/2] wait all goroutine done to avoid prefetcher close panic Signed-off-by: Keefe-Liu --- core/block_validator.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 7ef440b4b7..12fa908cd0 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -144,13 +144,15 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD validateRes <- tmpFunc() }() } + + var err error for i := 0; i < len(validateFuns); i++ { r := <-validateRes - if r != nil { - return r + if r != nil && err == nil { + err = r } } - return nil + return err } // CalcGasLimit computes the gas limit of the next block after parent. It aims