Fix Memory Leak In New Timecache Implementations (#528)

* fix bug

* add for last seen cache
This commit is contained in:
Nishant Das 2023-03-15 19:52:01 +08:00 committed by GitHub
parent 829f9026a3
commit 340387ef3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -26,8 +26,10 @@ func TestFirstSeenCacheExpire(t *testing.T) {
}
time.Sleep(2 * time.Second)
if tc.Has(fmt.Sprint(0)) {
t.Fatal("should have dropped this from the cache already")
for i := 0; i < 10; i++ {
if tc.Has(fmt.Sprint(i)) {
t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i))
}
}
}

View File

@ -25,8 +25,10 @@ func TestLastSeenCacheExpire(t *testing.T) {
}
time.Sleep(2 * time.Second)
if tc.Has(fmt.Sprint(0)) {
t.Fatal("should have dropped this from the cache already")
for i := 0; i < 11; i++ {
if tc.Has(fmt.Sprint(i)) {
t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i))
}
}
}

View File

@ -9,7 +9,7 @@ import (
var backgroundSweepInterval = time.Minute
func background(ctx context.Context, lk sync.Locker, m map[string]time.Time) {
ticker := time.NewTimer(backgroundSweepInterval)
ticker := time.NewTicker(backgroundSweepInterval)
defer ticker.Stop()
for {