forked from cerc-io/plugeth
core: added a running flag to prevent panics in the chainmanager
The running flag will determine whether the chain manager is still running or not. This will prevent the quit channel from being closed twice resulting in a panic. This PR should fix this issue. Closes #1559
This commit is contained in:
parent
e7f4232b10
commit
acd2c4e520
@ -77,6 +77,7 @@ type ChainManager struct {
|
||||
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
||||
|
||||
quit chan struct{}
|
||||
running int32 // running must be called automically
|
||||
// procInterrupt must be atomically called
|
||||
procInterrupt int32 // interrupt signaler for block processing
|
||||
wg sync.WaitGroup
|
||||
@ -443,6 +444,9 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
|
||||
}
|
||||
|
||||
func (bc *ChainManager) Stop() {
|
||||
if !atomic.CompareAndSwapInt32(&bc.running, 0, 1) {
|
||||
return
|
||||
}
|
||||
close(bc.quit)
|
||||
atomic.StoreInt32(&bc.procInterrupt, 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user