Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Memory Leak In New Timecache Implementations #528

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions timecache/first_seen_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions timecache/last_seen_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion timecache/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down