aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-08-03 22:15:19 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-08-03 22:15:19 +0800
commitcc6c5846e58b56a17395cc0ff7478b03bddfb6d5 (patch)
tree56eaf23845faed961047b0e577c6b04a8021d86c /core
parentdb988a46dd2e677f6a6c9e6946d97334ab9d0e6c (diff)
parentacd2c4e52028ec1e34358d6d79ada7812723b32e (diff)
downloaddexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar.gz
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar.bz2
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar.lz
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar.xz
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.tar.zst
dexon-cc6c5846e58b56a17395cc0ff7478b03bddfb6d5.zip
Merge pull request #1568 from obscuren/issue-1559
core: added a running flag to prevent panics in the chainmanager
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 91d1476a8..fc1d1304f 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -76,7 +76,8 @@ type ChainManager struct {
cache *lru.Cache // cache is the LRU caching
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 int32 // interrupt signaler for block processing
wg sync.WaitGroup
@@ -451,6 +452,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)