aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Frei <freisim93@gmail.com>2024-03-05 19:04:26 +0100
committerGitHub <noreply@github.com>2024-03-05 19:04:26 +0100
commit2ab2488274a2a5a857402fd65c949bddadbd7fad (patch)
tree003fc0f5b2e8e771567f1273426e2fb22ee34d81
parenteb9cd363d04997803beeb85d0ad6df0806a6537b (diff)
downloadsyncthing-2ab2488274a2a5a857402fd65c949bddadbd7fad.tar.gz
syncthing-2ab2488274a2a5a857402fd65c949bddadbd7fad.zip
lib/scanner: Fix ticker leak in scanner (fixes #9417) (#9451)
Move the ticker closer to where it's used and defer stop it to avoid missing a branch. Fixes regression introduced in https://github.com/syncthing/syncthing/commit/2f3eacdb6c1c33650ccdd91f42e842c116200d92 Fixes https://github.com/syncthing/syncthing/issues/9417
-rw-r--r--lib/scanner/walk.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/scanner/walk.go b/lib/scanner/walk.go
index 2f74dfa02..2397444b4 100644
--- a/lib/scanner/walk.go
+++ b/lib/scanner/walk.go
@@ -142,8 +142,6 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
w.ProgressTickIntervalS = 2
}
- ticker := time.NewTicker(time.Duration(w.ProgressTickIntervalS) * time.Second)
-
// We need to emit progress events, hence we create a routine which buffers
// the list of files to be hashed, counts the total number of
// bytes to hash, and once no more files need to be hashed (chan gets closed),
@@ -188,17 +186,17 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
})
}
+ ticker := time.NewTicker(time.Duration(w.ProgressTickIntervalS) * time.Second)
+ defer ticker.Stop()
for {
select {
case <-done:
emitProgressEvent()
l.Debugln(w, "Walk progress done", w.Folder, w.Subs, w.Matcher)
- ticker.Stop()
return
case <-ticker.C:
emitProgressEvent()
case <-ctx.Done():
- ticker.Stop()
return
}
}