From f42f041f5329f08117624d79fe25ed5e695f5e85 Mon Sep 17 00:00:00 2001 From: tomasz1986 Date: Sat, 22 Jul 2023 23:25:03 +0200 Subject: [PATCH] lib/ur: Don't report uptime if start time is in the past (fixes #7698) (#8996) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, because of devices with unset RTC clock, the 100% percentile for Uptime on [1] is calculated since the Unix epoch which is useless as far as usage statistics are concerned. Thus, if the Syncthing start time is set to a past date, assume that the clock is wrong and do not even try to report the uptime. [1] https://data.syncthing.net Signed-off-by: Tomasz WilczyƄski Co-authored-by: Jakob Borg --- lib/ur/usage_report.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ur/usage_report.go b/lib/ur/usage_report.go index 9b5cccddf..ce6984a4c 100644 --- a/lib/ur/usage_report.go +++ b/lib/ur/usage_report.go @@ -328,6 +328,11 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) ( } func (*Service) UptimeS() int { + // Handle nonexistent or wildly incorrect system clock. + // This code was written in 2023, it can't run in the past. + if StartTime.Year() < 2023 { + return 0 + } return int(time.Since(StartTime).Seconds()) }