diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-16 01:44:30 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-16 01:44:30 +0800 |
commit | cefe5c80b1cdcab606a169c0be65d9d2ba9bc941 (patch) | |
tree | dbbb116fa71ee396fdeb743a725b14007b43e845 /miner/worker.go | |
parent | 2f1f2e4811a6f3094f99b55f6553fe27d83f9aad (diff) | |
parent | 402fd6e8c6a2e379351e0aae10a833fae6bcae6c (diff) | |
download | go-tangerine-cefe5c80b1cdcab606a169c0be65d9d2ba9bc941.tar.gz go-tangerine-cefe5c80b1cdcab606a169c0be65d9d2ba9bc941.tar.zst go-tangerine-cefe5c80b1cdcab606a169c0be65d9d2ba9bc941.zip |
Merge pull request #1898 from karalabe/eventmux-post-race
core, eth, event, miner, xeth: fix event post / subscription race
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 19 |
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) { |