diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-01 18:32:28 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-01 18:32:28 +0800 |
commit | acd2c4e52028ec1e34358d6d79ada7812723b32e (patch) | |
tree | e905a4e0c3ae76294d8aef3b8ce3804620028a1d /core | |
parent | e7f4232b10034d291d1757b96e6277908618223c (diff) | |
download | go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar.gz go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar.bz2 go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar.lz go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar.xz go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.tar.zst go-tangerine-acd2c4e52028ec1e34358d6d79ada7812723b32e.zip |
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
Diffstat (limited to 'core')
-rw-r--r-- | core/chain_manager.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index c2e89a10d..0362e5ccc 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 @@ -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) |