Skip to content

Commit dacf445

Browse files
committed
libn/networkdb: don't exceed broadcast size limit
NetworkDB uses a hierarchy of queues to prioritize messages for broadcast. Unfortunately the logic to pull from multiple queues is flawed. The length of the messages pulled from the first queue is not taken into account when pulling messages from the second queue. A list of messages up to tiwce as long as the limit could be returned! Messages beyond the limit will be truncated unceremoniously by memberlist. Memberlist broadcast queues assume that all messages returned from a GetBroadcasts call will be broadcasted to other nodes in the cluster. Messages are popped from the queue once they have hit their retransmit limit. On a busy system messages may be broadcast fewer times than intended, possibly even being dropped without ever being broadcast! Subtract the length of messages pulled from the first queue from the broadcast size limit so the limit is not exceeded when pulling from the second queue. Signed-off-by: Cory Snider <[email protected]>
1 parent d71afd7 commit dacf445

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

libnetwork/networkdb/delegate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ func (d *delegate) NotifyMsg(buf []byte) {
408408

409409
func (d *delegate) GetBroadcasts(overhead, limit int) [][]byte {
410410
msgs := d.nDB.networkBroadcasts.GetBroadcasts(overhead, limit)
411-
msgs = append(msgs, d.nDB.nodeBroadcasts.GetBroadcasts(overhead, limit)...)
411+
for _, m := range msgs {
412+
limit -= overhead + len(m)
413+
}
414+
if limit > 0 {
415+
msgs = append(msgs, d.nDB.nodeBroadcasts.GetBroadcasts(overhead, limit)...)
416+
}
412417
return msgs
413418
}
414419

0 commit comments

Comments
 (0)