From e2e7ca9917882e87a60ec406fcce97872bdcc1aa Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Sat, 10 Dec 2022 22:14:57 +0800 Subject: [PATCH] fix: ntp should only cache no error result --- service/common/ntp/ntp.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/service/common/ntp/ntp.go b/service/common/ntp/ntp.go index a8b8bdb7..9abf72bf 100644 --- a/service/common/ntp/ntp.go +++ b/service/common/ntp/ntp.go @@ -27,9 +27,11 @@ func IsDatetimeSynced() (ok bool, t time.Time, err error) { return ntpSyncCache.value, ntpSyncCache.realTime, nil } defer func() { - ntpSyncCache.value = ok - ntpSyncCache.lastReq = time.Now() - ntpSyncCache.realTime = t + if err == nil { + ntpSyncCache.value = ok + ntpSyncCache.lastReq = time.Now() + ntpSyncCache.realTime = t + } }() t, err = ntp.Time("ntp.aliyun.com") if err != nil {