fix: ntp should only cache no error result

This commit is contained in:
mzz2017 committed 2022-12-10 22:14:57 +08:00
1 parent 816baefa11
commit e2e7ca9917
1 file changed
+5 -3
+5 -3
View File
@@ -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 {