diff options
author | zelig <viktor.tron@gmail.com> | 2015-04-08 01:53:05 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-09 20:58:35 +0800 |
commit | 42fb9652f56321d2752ffe7773806df11f3087b8 (patch) | |
tree | a78446ca225ec280e5e2dea83d4a80cfea7239f3 /blockpool/blockpool.go | |
parent | 30830652ae9ca15d1d9e1d32a22f9af671ae8a5a (diff) | |
download | dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar.gz dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar.bz2 dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar.lz dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar.xz dexon-42fb9652f56321d2752ffe7773806df11f3087b8.tar.zst dexon-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/blockpool.go')
-rw-r--r-- | blockpool/blockpool.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go index 3b3de928d..9871c5036 100644 --- a/blockpool/blockpool.go +++ b/blockpool/blockpool.go @@ -624,6 +624,7 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { entry := self.get(hash) // a peer's current head block is appearing the first time + sender.lock.Lock() if hash == sender.currentBlockHash { if sender.currentBlock == nil { plog.Debugf("AddBlock: add head block %s for peer <%s> (head: %s)", hex(hash), peerId, hex(sender.currentBlockHash)) @@ -634,16 +635,28 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { self.status.values.Blocks++ self.status.values.BlocksInPool++ self.status.lock.Unlock() + select { + case sender.currentBlockC <- block: + case <-sender.switchC: + } } else { plog.DebugDetailf("AddBlock: head block %s for peer <%s> (head: %s) already known", hex(hash), peerId, hex(sender.currentBlockHash)) // signal to head section process - sender.currentBlockC <- block } + // self.wg.Add(1) + // go func() { + // timeout := time.After(1 * time.Second) + // select { + // case sender.currentBlockC <- block: + // case <-timeout: + // } + // self.wg.Done() + // }() + } else { plog.DebugDetailf("AddBlock: block %s received from peer <%s> (head: %s)", hex(hash), peerId, hex(sender.currentBlockHash)) - sender.lock.Lock() // update peer chain info if more recent than what we registered if block.Td != nil && block.Td.Cmp(sender.td) > 0 { sender.td = block.Td @@ -652,7 +665,6 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { sender.currentBlock = block sender.headSection = nil } - sender.lock.Unlock() /* @zelig !!! requested 5 hashes from both A & B. A responds sooner then B, process blocks. Close section. @@ -668,6 +680,8 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { } */ } + sender.lock.Unlock() + if entry == nil { return } |