From 5abeab4008520698c6c0967a27f19c8d58e46703 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Sun, 3 Oct 2021 23:36:34 +0200 Subject: [PATCH] stop Ticker after use to prevent the memory leak https://github.com/golang/go/wiki/CodeReviewConcurrency#ticker-stop --- backend/app/migrator/backup.go | 1 + backend/app/store/image/image.go | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/app/migrator/backup.go b/backend/app/migrator/backup.go index e68a9bc7..ec22a24a 100644 --- a/backend/app/migrator/backup.go +++ b/backend/app/migrator/backup.go @@ -27,6 +27,7 @@ type AutoBackup struct { func (ab AutoBackup) Do(ctx context.Context) { log.Printf("[INFO] activate auto-backup for %s under %s, duration %s", ab.SiteID, ab.BackupLocation, ab.Duration) tick := time.NewTicker(ab.Duration) + defer tick.Stop() log.Printf("[DEBUG] first backup for %s at %s", ab.SiteID, time.Now().Add(ab.Duration)) for { diff --git a/backend/app/store/image/image.go b/backend/app/store/image/image.go index b7e10669..80a5e557 100644 --- a/backend/app/store/image/image.go +++ b/backend/app/store/image/image.go @@ -215,6 +215,7 @@ func (s *Service) Close(ctx context.Context) { waitForTerm := func(ctx context.Context) { ticker := time.NewTicker(10 * time.Millisecond) + defer ticker.Stop() for { select { case <-ctx.Done():