stop Ticker after use to prevent the memory leak
https://github.com/golang/go/wiki/CodeReviewConcurrency#ticker-stop
This commit is contained in:
committed by
Umputun
parent
7f575c4dd7
commit
5abeab4008
@@ -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 {
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user