From 80cec2674fb1c0c32547bf540e84b100b6658925 Mon Sep 17 00:00:00 2001 From: akkuman <1075768094@qq.com> Date: Fri, 9 Aug 2024 10:27:45 +0800 Subject: [PATCH] :bug: time.After memory leak before go1.23 (#5) --- sync_lock.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sync_lock.go b/sync_lock.go index 8a280a4..f936b3c 100644 --- a/sync_lock.go +++ b/sync_lock.go @@ -72,11 +72,13 @@ func (repo *Repo) tryLockCloud(currentDeviceID string, context map[string]interf // 锁定成功,定时刷新锁 go func() { + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() for { select { case <-endRefreshLock: return - case <-time.After(30 * time.Second): + case <-ticker.C: if refershErr := repo.lockCloud0(currentDeviceID); nil != refershErr { logging.LogErrorf("refresh cloud repo lock failed: %s", refershErr) }