Commit 2c6be49d authored by Péter Szilágyi's avatar Péter Szilágyi Committed by GitHub

Merge pull request #2949 from elliots/fix/#2948

miner: Prevent attempts to close nil quit channel in agent (fixes #2948)
parents a42b7355 ac0f8b81
...@@ -45,6 +45,8 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent { ...@@ -45,6 +45,8 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent {
miner := &CpuAgent{ miner := &CpuAgent{
pow: pow, pow: pow,
index: index, index: index,
quit: make(chan struct{}),
workCh: make(chan *Work, 1),
} }
return miner return miner
...@@ -55,25 +57,15 @@ func (self *CpuAgent) Pow() pow.PoW { return self.pow } ...@@ -55,25 +57,15 @@ func (self *CpuAgent) Pow() pow.PoW { return self.pow }
func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch } func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch }
func (self *CpuAgent) Stop() { func (self *CpuAgent) Stop() {
self.mu.Lock()
defer self.mu.Unlock()
close(self.quit) close(self.quit)
} }
func (self *CpuAgent) Start() { func (self *CpuAgent) Start() {
self.mu.Lock()
defer self.mu.Unlock()
if !atomic.CompareAndSwapInt32(&self.isMining, 0, 1) { if !atomic.CompareAndSwapInt32(&self.isMining, 0, 1) {
return // agent already started return // agent already started
} }
self.quit = make(chan struct{})
// creating current op ch makes sure we're not closing a nil ch
// later on
self.workCh = make(chan *Work, 1)
go self.update() go self.update()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment