blockpool: add missing shutdown synchronization

This commit is contained in:
Felix Lange 2015-04-17 18:13:22 +02:00
parent 2e5a0f3cde
commit e7608c009e
1 changed files with 7 additions and 3 deletions

View File

@ -184,6 +184,7 @@ type BlockPool struct {
wg sync.WaitGroup // wg sync.WaitGroup //
quit chan bool // chan used for quitting parallel routines quit chan bool // chan used for quitting parallel routines
running bool // running bool //
evloopdone chan struct{}
} }
// public constructor // public constructor
@ -204,6 +205,7 @@ func New(
verifyPoW: verifyPoW, verifyPoW: verifyPoW,
chainEvents: chainEvents, chainEvents: chainEvents,
td: td, td: td,
evloopdone: make(chan struct{}),
} }
} }
@ -244,6 +246,7 @@ func (self *BlockPool) Start() {
// status update interval // status update interval
timer := time.NewTicker(self.Config.StatusUpdateInterval) timer := time.NewTicker(self.Config.StatusUpdateInterval)
go func() { go func() {
defer close(self.evloopdone)
for { for {
select { select {
case <-self.quit: case <-self.quit:
@ -290,6 +293,7 @@ func (self *BlockPool) Stop() {
self.tdSub.Unsubscribe() self.tdSub.Unsubscribe()
close(self.quit) close(self.quit)
<-self.evloopdone
self.lock.Lock() self.lock.Lock()
self.peers = nil self.peers = nil