From 39268c754a1d87b13bc1b8e98d2446e7db85632a Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 22 Dec 2020 11:59:09 +0100 Subject: [PATCH 1/3] Use a simple backoff for retrying the update - Not sleeping might be too fast for the DNS server to restart - Fix the link to the issue --- internal/home/controlupdate.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index dcf428b9..9e69617c 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -9,6 +9,7 @@ import ( "runtime" "strings" "syscall" + "time" "github.com/AdguardTeam/AdGuardHome/internal/sysutil" "github.com/AdguardTeam/AdGuardHome/internal/update" @@ -46,7 +47,8 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { Context.controlLock.Unlock() if err != nil && strings.HasSuffix(err.Error(), "i/o timeout") { // This case may happen while we're restarting DNS server - // https://github.com/AdguardTeam/AdGuardHome/internal/issues/934 + // https://github.com/AdguardTeam/AdGuardHome/issues/934 + time.Sleep(time.Duration(i) * time.Second) continue } break From 664ef85c6cd39762887c4b88f154af29c7ba44c6 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Thu, 24 Dec 2020 21:44:36 +0300 Subject: [PATCH 2/3] home: improve error handling --- internal/home/controlupdate.go | 39 ++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index 9e69617c..17b60645 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -2,12 +2,12 @@ package home import ( "encoding/json" + "errors" "net/http" "os" "os/exec" "path/filepath" "runtime" - "strings" "syscall" "time" @@ -20,6 +20,13 @@ type getVersionJSONRequest struct { RecheckNow bool `json:"recheck_now"` } +// temoraryError is the interface for temporary errors from the Go standard +// library. +type temoraryError interface { + error + Temporary() (ok bool) +} + // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { if Context.disableUpdate { @@ -42,15 +49,29 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { var info update.VersionInfo for i := 0; i != 3; i++ { - Context.controlLock.Lock() - info, err = Context.updater.GetVersionResponse(req.RecheckNow) - Context.controlLock.Unlock() - if err != nil && strings.HasSuffix(err.Error(), "i/o timeout") { - // This case may happen while we're restarting DNS server - // https://github.com/AdguardTeam/AdGuardHome/issues/934 - time.Sleep(time.Duration(i) * time.Second) - continue + func() { + Context.controlLock.Lock() + defer Context.controlLock.Unlock() + + info, err = Context.updater.GetVersionResponse(req.RecheckNow) + }() + + if err != nil { + var terr temoraryError + if errors.As(err, &terr) && terr.Temporary() { + // Temporary network error. This case may happen while + // we're restarting our DNS server. Log and sleep for + // some time. + // + // See https://github.com/AdguardTeam/AdGuardHome/issues/934. + d := time.Duration(i) * time.Second + log.Info("temp net error: %q; sleeping for %s and retrying", err, d) + time.Sleep(d) + + continue + } } + break } if err != nil { From 4bc1337cc9cb4f15f2fd93f638798a94339a2ed9 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 25 Dec 2020 12:54:22 +0300 Subject: [PATCH 3/3] home: imp naming --- internal/home/controlupdate.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index 17b60645..ff9dc4ab 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -20,9 +20,9 @@ type getVersionJSONRequest struct { RecheckNow bool `json:"recheck_now"` } -// temoraryError is the interface for temporary errors from the Go standard +// temporaryError is the interface for temporary errors from the Go standard // library. -type temoraryError interface { +type temporaryError interface { error Temporary() (ok bool) } @@ -57,7 +57,7 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { }() if err != nil { - var terr temoraryError + var terr temporaryError if errors.As(err, &terr) && terr.Temporary() { // Temporary network error. This case may happen while // we're restarting our DNS server. Log and sleep for