blockpool: add missing shutdown synchronization
This commit is contained in:
parent
2e5a0f3cde
commit
e7608c009e
|
@ -181,9 +181,10 @@ type BlockPool struct {
|
||||||
|
|
||||||
// waitgroup is used in tests to wait for result-critical routines
|
// waitgroup is used in tests to wait for result-critical routines
|
||||||
// as well as in determining idle / syncing status
|
// as well as in determining idle / syncing status
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue