Skip to content

Commit

Permalink
fix ttl_cache.removeExpiredLoop: remove Tick usage
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan.Makeev <[email protected]>
  • Loading branch information
Ranger-X committed Dec 4, 2024
1 parent 0f7e386 commit 631509e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions images/storage-network-controller/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func main() {
err := discoverer.DiscoveryLoop(ctx, *cfg, mgr)
if err != nil {
log.Error(err, "failed to discovery node")
cancel()
os.Exit(2)
}
}
Expand Down
6 changes: 5 additions & 1 deletion images/storage-network-controller/src/pkg/cache/ttl_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func NewTTL[K comparable, V any](ctx context.Context) *TTLCache[K, V] {

// Iterate over the cache items every 5 sec and delete expired ones.
func (c *TTLCache[K, V]) removeExpiredLoop(ctx context.Context) {
for range time.Tick(5 * time.Second) {
// endless loop
for {
select {
case <-ctx.Done():
// do nothing in case of cancel, just return from this gorouting
Expand All @@ -72,6 +73,9 @@ func (c *TTLCache[K, V]) removeExpiredLoop(ctx context.Context) {
}

c.mu.Unlock()

// sleep for 5 sec
time.Sleep(5 * time.Second)
}
}
}
Expand Down

0 comments on commit 631509e

Please sign in to comment.