From e4ab7b4ff3aabef95a25adb00fb376c25ae34637 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 13 Jun 2025 22:16:22 +0000 Subject: [PATCH] fix(watchaggregator): properly handle sub-second watch durations (fixes #9927) (#10179) I'll let Audrius words from the ticket explain this :) > I'm a bit lost, time.Duration is an int64, yet watcher delay is float, > anything sub 1s gets rounded down to 0, so you just end up going into an > infinite loop. https://github.com/syncthing/syncthing/issues/9927#issuecomment-2967736106 --- lib/watchaggregator/aggregator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/watchaggregator/aggregator.go b/lib/watchaggregator/aggregator.go index 19d316bb5..36412e1db 100644 --- a/lib/watchaggregator/aggregator.go +++ b/lib/watchaggregator/aggregator.go @@ -440,7 +440,7 @@ func (a *aggregator) updateConfig(folderCfg config.FolderConfiguration) { if maxDelay := folderCfg.FSWatcherTimeoutS; maxDelay > 0 { // FSWatcherTimeoutS is set explicitly so use that, but it also // can't be lower than FSWatcherDelayS - a.notifyTimeout = time.Duration(max(maxDelay, folderCfg.FSWatcherDelayS)) * time.Second + a.notifyTimeout = time.Duration(max(maxDelay, folderCfg.FSWatcherDelayS) * float64(time.Second)) } else { // Use the default FSWatcherTimeoutS calculation a.notifyTimeout = notifyTimeout(folderCfg.FSWatcherDelayS) @@ -471,10 +471,10 @@ func notifyTimeout(eventDelayS float64) time.Duration { longDelayTimeout = time.Minute ) if eventDelayS < shortDelayS { - return time.Duration(eventDelayS*shortDelayMultiplicator) * time.Second + return time.Duration(eventDelayS * shortDelayMultiplicator * float64(time.Second)) } if eventDelayS < longDelayS { return longDelayTimeout } - return time.Duration(eventDelayS) * time.Second + return time.Duration(eventDelayS * float64(time.Second)) }