diff --git a/sublist/sublist.go b/sublist/sublist.go index 88ed3d8a..8d23c8d1 100644 --- a/sublist/sublist.go +++ b/sublist/sublist.go @@ -163,10 +163,9 @@ func (s *Sublist) removeFromCache(subject []byte, sub interface{}) { if !matchLiteral(k, subject) { continue } - r := s.cache.Get(k) - if r == nil { - continue - } + // FIXME, right now just remove all matching cache + // entries. Should be smarter and walk small result + // lists and delete s.cache.Remove(k) } } @@ -209,7 +208,10 @@ func (s *Sublist) Match(subject []byte) []interface{} { if int(s.cache.Count()) >= s.cmax { s.cache.RemoveRandom() } - s.cache.Set(subject, results) + // Make sure we copy the subject key here + scopy := make([]byte, len(subject)) + copy(scopy, subject) + s.cache.Set(scopy, results) s.mu.Unlock() return results diff --git a/sublist/sublist_test.go b/sublist/sublist_test.go index 9a9ffbff..d38be06f 100644 --- a/sublist/sublist_test.go +++ b/sublist/sublist_test.go @@ -274,10 +274,9 @@ func TestStats(t *testing.T) { if stats.MaxFanout != 3 { t.Fatalf("Wrong stats for MaxFanout: %d vs %d\n", stats.MaxFanout, 3) } - if stats.AvgFanout != 2.5 { - t.Fatalf("Wrong stats for MaxFanout: %d vs %d\n", stats.AvgFanout, 2.5) + if stats.AvgFanout != 3.0 { + t.Fatalf("Wrong stats for AvgFanout: %g vs %g\n", stats.AvgFanout, 3.0) } - s.ResetStats() stats = s.Stats() if time.Since(stats.StatsTime) > 50*time.Millisecond {