Fallback to cache_file avoiding termination for not offline_mode (#1332)

Ignore downloading error from `NewSource` when startup (cache loaded).
This commit is contained in:
lifenjoiner 2020-05-30 14:38:04 +08:00 committed by GitHub
parent ee62eb7b23
commit c4a13d25ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -712,8 +712,11 @@ func (config *Config) loadSource(proxy *Proxy, requiredProps stamps.ServerInform
}
source, err := NewSource(cfgSourceName, proxy.xTransport, cfgSource.URLs, cfgSource.MinisignKeyStr, cfgSource.CacheFile, cfgSource.FormatStr, time.Duration(cfgSource.RefreshDelay)*time.Hour)
if err != nil {
dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err)
return err
if len(source.in) <= 0 {
dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err)
return err
}
dlog.Infof("Downloading [%s] failed: %v, use cache file to startup", source.name, err)
}
proxy.sources = append(proxy.sources, source)
registeredServers, err := source.Parse(cfgSource.Prefix)

View File

@ -211,7 +211,7 @@ func PrefetchSources(xTransport *XTransport, sources []*Source) time.Duration {
}
dlog.Debugf("Prefetching [%s]", source.name)
if delay, err := source.fetchWithCache(xTransport, now); err != nil {
dlog.Infof("Prefetching [%s] failed: %v", source.name, err)
dlog.Infof("Prefetching [%s] failed: %v, retry after %v", source.name, err, interval)
} else {
dlog.Debugf("Prefetching [%s] succeeded, next update: %v", source.name, delay)
if delay >= MinimumPrefetchInterval && (interval == MinimumPrefetchInterval || interval > delay) {