mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Make sure to copy cache keys
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user