Skip to content

Commit 9b5c180

Browse files
committed
[FAB-3335] Gossip pull may send zero-length digests
The bug was introduced in a recent commit that added filtering capability. Basically when the gossip puller gets a hello from a peer, it iterates over the items it has, and applies a filter on each of them. If the filter doesn't permit, it skips to the next iteration, but the returned slice then contains an "empty-string" digest in the response to the remote peer. While this isn't dangerous, this causes un-necessary messages to be sent so this should be fixed. Also added an optimization that if there are no digests/items to send, we don't return any response to the sender. Change-Id: Ic455413dc9e040ea98ef3bb0ee3531f2c6cfc32c Signed-off-by: Yacov Manevich <[email protected]>
1 parent d661d11 commit 9b5c180

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

gossip/gossip/algo/pull.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,17 @@ func (engine *PullEngine) OnHello(nonce uint64, context interface{}) {
291291
})
292292

293293
a := engine.state.ToArray()
294-
digest := make([]string, len(a))
294+
var digest []string
295295
filter := engine.digFilter(context)
296-
for i, item := range a {
296+
for _, item := range a {
297297
dig := item.(string)
298298
if !filter(dig) {
299299
continue
300300
}
301-
digest[i] = dig
301+
digest = append(digest, dig)
302+
}
303+
if len(digest) == 0 {
304+
return
302305
}
303306
engine.SendDigest(digest, nonce, context)
304307
}
@@ -309,6 +312,7 @@ func (engine *PullEngine) OnReq(items []string, nonce uint64, context interface{
309312
return
310313
}
311314
engine.lock.Lock()
315+
defer engine.lock.Unlock()
312316

313317
filter := engine.digFilter(context)
314318
var items2Send []string
@@ -318,7 +322,9 @@ func (engine *PullEngine) OnReq(items []string, nonce uint64, context interface{
318322
}
319323
}
320324

321-
engine.lock.Unlock()
325+
if len(items2Send) == 0 {
326+
return
327+
}
322328

323329
go engine.SendRes(items2Send, context, nonce)
324330
}

0 commit comments

Comments
 (0)