mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
core, eth: add missing shutdown synchronization to ChainManager
This commit is contained in:
parent
898ba87984
commit
2e5a0f3cde
2 changed files with 7 additions and 0 deletions
|
|
@ -92,6 +92,7 @@ type ChainManager struct {
|
||||||
futureBlocks *BlockCache
|
futureBlocks *BlockCache
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *ChainManager {
|
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.futureBlocks = NewBlockCache(254)
|
||||||
bc.makeCache()
|
bc.makeCache()
|
||||||
|
|
||||||
|
bc.wg.Add(1)
|
||||||
go bc.update()
|
go bc.update()
|
||||||
|
|
||||||
return bc
|
return bc
|
||||||
|
|
@ -423,6 +425,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
|
||||||
|
|
||||||
func (bc *ChainManager) Stop() {
|
func (bc *ChainManager) Stop() {
|
||||||
close(bc.quit)
|
close(bc.quit)
|
||||||
|
bc.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
type queueEvent struct {
|
type queueEvent struct {
|
||||||
|
|
@ -588,6 +591,9 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) {
|
||||||
func (self *ChainManager) update() {
|
func (self *ChainManager) update() {
|
||||||
events := self.eventMux.Subscribe(queueEvent{})
|
events := self.eventMux.Subscribe(queueEvent{})
|
||||||
futureTimer := time.NewTicker(5 * time.Second)
|
futureTimer := time.NewTicker(5 * time.Second)
|
||||||
|
defer self.wg.Done()
|
||||||
|
defer futureTimer.Stop()
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,7 @@ func (s *Ethereum) Stop() {
|
||||||
s.txSub.Unsubscribe() // quits txBroadcastLoop
|
s.txSub.Unsubscribe() // quits txBroadcastLoop
|
||||||
s.blockSub.Unsubscribe() // quits blockBroadcastLoop
|
s.blockSub.Unsubscribe() // quits blockBroadcastLoop
|
||||||
|
|
||||||
|
s.chainManager.Stop()
|
||||||
s.txPool.Stop()
|
s.txPool.Stop()
|
||||||
s.eventMux.Stop()
|
s.eventMux.Stop()
|
||||||
s.blockPool.Stop()
|
s.blockPool.Stop()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue