stop Ticker after use to prevent the memory leak

https://github.com/golang/go/wiki/CodeReviewConcurrency#ticker-stop
This commit is contained in:
Dmitry Verkhoturov
2021-10-03 16:09:30 -06:00
committed by Umputun
parent 7f575c4dd7
commit 5abeab4008
2 changed files with 2 additions and 0 deletions
+1
View File
@@ -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 {
+1
View File
@@ -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():