aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/peers.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-04-08 01:53:05 +0800
committerzelig <viktor.tron@gmail.com>2015-04-09 20:58:35 +0800
commit42fb9652f56321d2752ffe7773806df11f3087b8 (patch)
treea78446ca225ec280e5e2dea83d4a80cfea7239f3 /blockpool/peers.go
parent30830652ae9ca15d1d9e1d32a22f9af671ae8a5a (diff)
downloadgo-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar.gz
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar.bz2
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar.lz
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar.xz
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.tar.zst
go-tangerine-42fb9652f56321d2752ffe7773806df11f3087b8.zip
fix blockpool deadlock
- do not break from headsection on error [remove peer after protocol quit will close switchC, until then head block can arrive and block on channel while keeping peers lock causing a deadlock.] - more careful locking in AddBlock
Diffstat (limited to 'blockpool/peers.go')
-rw-r--r--blockpool/peers.go10
1 files changed, 1 insertions, 9 deletions
diff --git a/blockpool/peers.go b/blockpool/peers.go
index 59225856d..d95c348a8 100644
--- a/blockpool/peers.go
+++ b/blockpool/peers.go
@@ -142,9 +142,8 @@ func (self *peer) setChainInfo(td *big.Int, c common.Hash) {
self.headSection = nil
}
+// caller must hold peer lock
func (self *peer) setChainInfoFromBlock(block *types.Block) {
- self.lock.Lock()
- defer self.lock.Unlock()
// use the optional TD to update peer td, this helps second best peer selection
// in case best peer is lost
if block.Td != nil && block.Td.Cmp(self.td) > 0 {
@@ -155,11 +154,6 @@ func (self *peer) setChainInfoFromBlock(block *types.Block) {
self.currentBlock = block
self.headSection = nil
}
- self.bp.wg.Add(1)
- go func() {
- self.currentBlockC <- block
- self.bp.wg.Done()
- }()
}
// distribute block request among known peers
@@ -571,7 +565,6 @@ LOOP:
self.bp.status.badPeers[self.id]++
self.bp.status.lock.Unlock()
// there is no persistence here, so GC will just take care of cleaning up
- break LOOP
// signal for peer switch, quit
case <-switchC:
@@ -594,7 +587,6 @@ LOOP:
self.bp.status.badPeers[self.id]++
self.bp.status.lock.Unlock()
plog.Debugf("HeadSection: <%s> (headsection [%s]) quit channel closed : timed out without providing new blocks...quitting", self.id, sectionhex(self.headSection))
- break LOOP
}
}
if !self.idle {