Skip to content

Commit cc6c584

Browse files
committed
Merge pull request #1568 from obscuren/issue-1559
core: added a running flag to prevent panics in the chainmanager
2 parents db988a4 + acd2c4e commit cc6c584

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/chain_manager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ type ChainManager struct {
7676
cache *lru.Cache // cache is the LRU caching
7777
futureBlocks *lru.Cache // future blocks are blocks added for later processing
7878

79-
quit chan struct{}
79+
quit chan struct{}
80+
running int32 // running must be called automically
8081
// procInterrupt must be atomically called
8182
procInterrupt int32 // interrupt signaler for block processing
8283
wg sync.WaitGroup
@@ -451,6 +452,9 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
451452
}
452453

453454
func (bc *ChainManager) Stop() {
455+
if !atomic.CompareAndSwapInt32(&bc.running, 0, 1) {
456+
return
457+
}
454458
close(bc.quit)
455459
atomic.StoreInt32(&bc.procInterrupt, 1)
456460

0 commit comments

Comments
 (0)