Merge pull request #1485 from weaveworks/1450-check-slice
Sanity-check gossip messages
This commit is contained in:
commit
cd8befe43e
1 file changed
+7
@@ -148,11 +148,18 @@ func (c *GossipChannel) gcSenders(connections ConnectionSet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have seen a couple of failures which suggest a >128GB slice was encountered.
|
||||||
|
// 100MB should be enough for anyone.
|
||||||
|
const maxFeasibleMessageLen = 100 * 1024 * 1024
|
||||||
|
|
||||||
func (c *GossipChannel) sendDown(conn Connection, data GossipData) {
|
func (c *GossipChannel) sendDown(conn Connection, data GossipData) {
|
||||||
sender, found := c.senders[conn]
|
sender, found := c.senders[conn]
|
||||||
if !found {
|
if !found {
|
||||||
sender = NewGossipSender(func(pending GossipData) {
|
sender = NewGossipSender(func(pending GossipData) {
|
||||||
for _, msg := range pending.Encode() {
|
for _, msg := range pending.Encode() {
|
||||||
|
if len(msg) > maxFeasibleMessageLen {
|
||||||
|
panic(fmt.Sprintf("Gossip message too large: len=%d bytes; on channel '%s' from %+v", len(msg), c.name, pending))
|
||||||
|
}
|
||||||
protocolMsg := ProtocolMsg{ProtocolGossip, GobEncode(c.name, c.ourself.Name, msg)}
|
protocolMsg := ProtocolMsg{ProtocolGossip, GobEncode(c.name, c.ourself.Name, msg)}
|
||||||
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
|
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user