core, eth: add missing shutdown synchronization to ChainManager

This commit is contained in:
Felix Lange
2015-04-17 18:12:25 +02:00
parent 898ba87984
commit 2e5a0f3cde
2 changed files with 7 additions and 0 deletions

View File

@ -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 {

View File

@ -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()