nflog: Fix Log() crash when gossip is nil (#1064)

This commit is contained in:
Julius Volz 2017-11-01 09:34:40 +00:00 committed by stuart nelson
parent 359b614f5f
commit fc984941ee
2 changed files with 14 additions and 3 deletions

View File

@ -360,9 +360,11 @@ func (l *nlog) Log(r *pb.Receiver, gkey string, firingAlerts, resolvedAlerts []u
},
ExpiresAt: now.Add(l.retention),
}
l.gossip.GossipBroadcast(gossipData{
key: e,
})
if l.gossip != nil {
l.gossip.GossipBroadcast(gossipData{
key: e,
})
}
l.st[key] = e
return nil

View File

@ -264,3 +264,12 @@ func TestGossipDataCoding(t *testing.T) {
require.Equal(t, in, out, "decoded data doesn't match encoded data")
}
}
func TestNilGossipDoesNotCrash(t *testing.T) {
nl, err := New()
if err != nil {
require.NoError(t, err, "constructing nflog failed")
}
err = nl.Log(&pb.Receiver{}, "key", []uint64{}, []uint64{})
require.NoError(t, err, "logging notification failed")
}