🎨 Improve data sync network connectivity check Fix https://github.com/siyuan-note/siyuan/issues/9251

This commit is contained in:
Daniel 2023-09-22 09:24:41 +08:00
parent f5f9b1a393
commit 388ab0a352
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -55,6 +55,7 @@ func isOnline(checkURL string, skipTlsVerify bool) (ret bool) {
if skipTlsVerify {
c.EnableInsecureSkipVerify()
}
c.SetUserAgent(UserAgent)
for i := 0; i < 3; i++ {
resp, err := c.R().Get(checkURL)
@ -66,6 +67,7 @@ func isOnline(checkURL string, skipTlsVerify bool) (ret bool) {
case *url.Error:
if err.(*url.Error).URL != checkURL {
// DNS 重定向
logging.LogWarnf("network is online [DNS redirect, checkURL=%s, retURL=%s]", checkURL, err.(*url.Error).URL)
return true
}
}
@ -74,6 +76,9 @@ func isOnline(checkURL string, skipTlsVerify bool) (ret bool) {
if ret {
break
}
time.Sleep(1 * time.Second)
logging.LogWarnf("check url [%s] is online failed: %s", checkURL, err)
}
return
}