Skip to content

Commit 340387e

Browse files
authored
Fix Memory Leak In New Timecache Implementations (#528)
* fix bug * add for last seen cache
1 parent 829f902 commit 340387e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

timecache/first_seen_cache_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ func TestFirstSeenCacheExpire(t *testing.T) {
2626
}
2727

2828
time.Sleep(2 * time.Second)
29-
if tc.Has(fmt.Sprint(0)) {
30-
t.Fatal("should have dropped this from the cache already")
29+
for i := 0; i < 10; i++ {
30+
if tc.Has(fmt.Sprint(i)) {
31+
t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i))
32+
}
3133
}
3234
}
3335

timecache/last_seen_cache_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ func TestLastSeenCacheExpire(t *testing.T) {
2525
}
2626

2727
time.Sleep(2 * time.Second)
28-
if tc.Has(fmt.Sprint(0)) {
29-
t.Fatal("should have dropped this from the cache already")
28+
for i := 0; i < 11; i++ {
29+
if tc.Has(fmt.Sprint(i)) {
30+
t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i))
31+
}
3032
}
3133
}
3234

timecache/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
var backgroundSweepInterval = time.Minute
1010

1111
func background(ctx context.Context, lk sync.Locker, m map[string]time.Time) {
12-
ticker := time.NewTimer(backgroundSweepInterval)
12+
ticker := time.NewTicker(backgroundSweepInterval)
1313
defer ticker.Stop()
1414

1515
for {

0 commit comments

Comments
 (0)