From e334478214e1359d400f2c879a0340ed0cd88161 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 8 Oct 2024 17:06:13 +0800 Subject: [PATCH] :art: Improve WebDAV/S3 data sync request timeout settings https://github.com/siyuan-note/siyuan/issues/12734 --- kernel/bazaar/package.go | 2 +- kernel/model/sync.go | 5 ++++- kernel/util/net.go | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index e9f4df7a3..2a8cc6ab8 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -484,7 +484,7 @@ func isOutdatedTemplate(template *Template, bazaarTemplates []*Template) bool { func isBazzarOnline() (ret bool) { // Improve marketplace loading when offline https://github.com/siyuan-note/siyuan/issues/12050 - ret = util.IsOnline(util.BazaarOSSServer, true) + ret = util.IsOnline(util.BazaarOSSServer, true, 3000) if !ret { util.PushErrMsg(util.Langs[util.Lang][24], 5000) } diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 3268d4fdc..b657497f1 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -648,20 +648,23 @@ func planSyncAfter(d time.Duration) { func isProviderOnline(byHand bool) (ret bool) { checkURL := util.GetCloudSyncServer() skipTlsVerify := false + timeout := 3000 switch Conf.Sync.Provider { case conf.ProviderSiYuan: case conf.ProviderS3: checkURL = Conf.Sync.S3.Endpoint skipTlsVerify = Conf.Sync.S3.SkipTlsVerify + timeout = Conf.Sync.S3.Timeout * 1000 case conf.ProviderWebDAV: checkURL = Conf.Sync.WebDAV.Endpoint skipTlsVerify = Conf.Sync.WebDAV.SkipTlsVerify + timeout = Conf.Sync.WebDAV.Timeout * 1000 default: logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider) return false } - if ret = util.IsOnline(checkURL, skipTlsVerify); !ret { + if ret = util.IsOnline(checkURL, skipTlsVerify, timeout); !ret { if 1 > autoSyncErrCount || byHand { util.PushErrMsg(Conf.Language(76)+" (Provider: "+conf.ProviderToStr(Conf.Sync.Provider)+")", 5000) } diff --git a/kernel/util/net.go b/kernel/util/net.go index 94d6f91ae..60b8a2fe9 100644 --- a/kernel/util/net.go +++ b/kernel/util/net.go @@ -72,7 +72,7 @@ func IsLocalOrigin(origin string) bool { return false } -func IsOnline(checkURL string, skipTlsVerify bool) bool { +func IsOnline(checkURL string, skipTlsVerify bool, timeout int) bool { _, err := url.Parse(checkURL) if err != nil { logging.LogWarnf("invalid check URL [%s]", checkURL) @@ -83,7 +83,7 @@ func IsOnline(checkURL string, skipTlsVerify bool) bool { return false } - if isOnline(checkURL, skipTlsVerify) { + if isOnline(checkURL, skipTlsVerify, timeout) { return true } @@ -104,8 +104,8 @@ func IsPortOpen(port string) bool { return false } -func isOnline(checkURL string, skipTlsVerify bool) (ret bool) { - c := req.C().SetTimeout(3 * time.Second) +func isOnline(checkURL string, skipTlsVerify bool, timeout int) (ret bool) { + c := req.C().SetTimeout(time.Duration(timeout) * time.Millisecond) if skipTlsVerify { c.EnableInsecureSkipVerify() }