diff --git a/core/chain_manager.go b/core/chain_manager.go index 7e792864a5..03250db928 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -92,6 +92,7 @@ type ChainManager struct { futureBlocks *BlockCache quit chan struct{} + wg sync.WaitGroup } func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *ChainManager { @@ -104,6 +105,7 @@ func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *Chai bc.futureBlocks = NewBlockCache(254) bc.makeCache() + bc.wg.Add(1) go bc.update() return bc @@ -423,6 +425,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) { func (bc *ChainManager) Stop() { close(bc.quit) + bc.wg.Wait() } type queueEvent struct { @@ -588,6 +591,9 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) { func (self *ChainManager) update() { events := self.eventMux.Subscribe(queueEvent{}) futureTimer := time.NewTicker(5 * time.Second) + defer self.wg.Done() + defer futureTimer.Stop() + out: for { select { diff --git a/eth/backend.go b/eth/backend.go index bb1091f23d..eb1fd8c6ce 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -433,6 +433,7 @@ func (s *Ethereum) Stop() { s.txSub.Unsubscribe() // quits txBroadcastLoop s.blockSub.Unsubscribe() // quits blockBroadcastLoop + s.chainManager.Stop() s.txPool.Stop() s.eventMux.Stop() s.blockPool.Stop()