network: remove priority queue from block queue
Use circular buffer which is a bit more appropriate. The problem is that priority queue accepts and stores equal items which wastes memory even in normal usage scenario, but it's especially dangerous if the node is stuck for some reason. In this case it'll accept from peers and put into queue the same blocks again and again leaking memory up to OOM condition. Notice that queue length calculation might be wrong in case circular buffer wraps, but it's not very likely to happen (usually blocks not coming from the queue are added by consensus and it's not very fast in doing so).
This commit is contained in:
parent
fdf80dbdc5
commit
8bb1ecb45a
7 changed files with 70 additions and 63 deletions
|
@ -74,3 +74,10 @@ func TestBlockQueue(t *testing.T) {
|
|||
bq.discard()
|
||||
assert.Equal(t, 0, bq.length())
|
||||
}
|
||||
|
||||
// length wraps len access for tests to make them thread-safe.
|
||||
func (bq *blockQueue) length() int {
|
||||
bq.queueLock.Lock()
|
||||
defer bq.queueLock.Unlock()
|
||||
return bq.len
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue