aboutsummaryrefslogtreecommitdiffstats
path: root/miner/worker.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-10-12 20:04:38 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-10-12 21:22:03 +0800
commit402fd6e8c6a2e379351e0aae10a833fae6bcae6c (patch)
tree30ab93e93af7c70e5df213eb3665f51a293bc4a9 /miner/worker.go
parent315a422ba754eae10db21990a809f608f7af62d4 (diff)
downloaddexon-402fd6e8c6a2e379351e0aae10a833fae6bcae6c.tar.gz
dexon-402fd6e8c6a2e379351e0aae10a833fae6bcae6c.tar.zst
dexon-402fd6e8c6a2e379351e0aae10a833fae6bcae6c.zip
core, eth, event, miner, xeth: fix event post / subscription race
Diffstat (limited to 'miner/worker.go')
-rw-r--r--miner/worker.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/miner/worker.go b/miner/worker.go
index 8be2db93e..43f6f9909 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -215,13 +215,20 @@ func (self *worker) register(agent Agent) {
}
func (self *worker) update() {
- events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
+ eventSub := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
+ defer eventSub.Unsubscribe()
-out:
+ eventCh := eventSub.Chan()
for {
select {
- case event := <-events.Chan():
- switch ev := event.(type) {
+ case event, ok := <-eventCh:
+ if !ok {
+ // Event subscription closed, set the channel to nil to stop spinning
+ eventCh = nil
+ continue
+ }
+ // A real event arrived, process interesting content
+ switch ev := event.Data.(type) {
case core.ChainHeadEvent:
self.commitNewWork()
case core.ChainSideEvent:
@@ -237,11 +244,9 @@ out:
}
}
case <-self.quit:
- break out
+ return
}
}
-
- events.Unsubscribe()
}
func newLocalMinedBlock(blockNumber uint64, prevMinedBlocks *uint64RingBuffer) (minedBlocks *uint64RingBuffer) {