Merge pull request #1568 from obscuren/issue-1559
core: added a running flag to prevent panics in the chainmanager
This commit is contained in:
commit
cc6c5846e5
@ -77,6 +77,7 @@ type ChainManager struct {
|
|||||||
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
running int32 // running must be called automically
|
||||||
// procInterrupt must be atomically called
|
// procInterrupt must be atomically called
|
||||||
procInterrupt int32 // interrupt signaler for block processing
|
procInterrupt int32 // interrupt signaler for block processing
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
@ -451,6 +452,9 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) Stop() {
|
func (bc *ChainManager) Stop() {
|
||||||
|
if !atomic.CompareAndSwapInt32(&bc.running, 0, 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
close(bc.quit)
|
close(bc.quit)
|
||||||
atomic.StoreInt32(&bc.procInterrupt, 1)
|
atomic.StoreInt32(&bc.procInterrupt, 1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user