From 380cff07f2142a24e4dfa206fee8436d3231826b Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Tue, 28 Dec 2021 17:25:43 +0300 Subject: [PATCH] Pull request: all: opt log levels more Updates #3929. Squashed commit of the following: commit 0d4aadeff1c4de1440795faf83eb072c46392ff3 Author: Ainar Garipov Date: Tue Dec 28 16:34:44 2021 +0300 all: opt log levels more --- go.mod | 2 +- go.sum | 4 ++-- internal/dhcpd/v4.go | 2 -- internal/dhcpd/v6.go | 7 +++++-- internal/home/web.go | 50 ++++++++++++++++++++++++++++---------------- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 0988e3a4..c082bfff 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome go 1.17 require ( - github.com/AdguardTeam/dnsproxy v0.40.1 + github.com/AdguardTeam/dnsproxy v0.40.2 github.com/AdguardTeam/golibs v0.10.3 github.com/AdguardTeam/urlfilter v0.15.1 github.com/NYTimes/gziphandler v1.1.1 diff --git a/go.sum b/go.sum index 0ee66fd4..53d958d7 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -github.com/AdguardTeam/dnsproxy v0.40.1 h1:lYNi7VeCBhmdyf5xEUxfj84ikgiz5cjzocL9moiIRhk= -github.com/AdguardTeam/dnsproxy v0.40.1/go.mod h1:PZ9l22h3Er+5mxFQB7oHZMTvx+aa9R6LbzA/ikXQlS0= +github.com/AdguardTeam/dnsproxy v0.40.2 h1:GG4StH+d4rB7YW3d20sdQjJG8URUeaIQicnEAsYJY7w= +github.com/AdguardTeam/dnsproxy v0.40.2/go.mod h1:PZ9l22h3Er+5mxFQB7oHZMTvx+aa9R6LbzA/ikXQlS0= github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.9.2/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY= diff --git a/internal/dhcpd/v4.go b/internal/dhcpd/v4.go index 0107eddf..e7dc0571 100644 --- a/internal/dhcpd/v4.go +++ b/internal/dhcpd/v4.go @@ -1056,8 +1056,6 @@ func (s *v4Server) Start() (err error) { go func() { if serr := s.srv.Serve(); errors.Is(serr, net.ErrClosed) { log.Info("dhcpv4: server is closed") - - return } else if serr != nil { log.Error("dhcpv4: srv.Serve: %s", serr) } diff --git a/internal/dhcpd/v6.go b/internal/dhcpd/v6.go index 625f99be..b483384d 100644 --- a/internal/dhcpd/v6.go +++ b/internal/dhcpd/v6.go @@ -662,8 +662,11 @@ func (s *v6Server) Start() (err error) { } go func() { - err = s.srv.Serve() - log.Error("dhcpv6: srv.Serve: %s", err) + if serr := s.srv.Serve(); errors.Is(serr, net.ErrClosed) { + log.Info("dhcpv6: server is closed") + } else if serr != nil { + log.Error("dhcpv6: srv.Serve: %s", serr) + } }() return nil diff --git a/internal/home/web.go b/internal/home/web.go index 07f9d73a..54fb1324 100644 --- a/internal/home/web.go +++ b/internal/home/web.go @@ -10,6 +10,7 @@ import ( "time" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" + "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/netutil" "github.com/NYTimes/gziphandler" @@ -175,35 +176,48 @@ func (web *Web) Start() { WriteTimeout: web.conf.WriteTimeout, } go func() { + defer log.OnPanic("web: plain") + errs <- web.httpServer.ListenAndServe() }() - if web.conf.BetaBindPort != 0 { - web.httpServerBeta = &http.Server{ - ErrorLog: log.StdLog("web: plain", log.DEBUG), - Addr: netutil.JoinHostPort(hostStr, web.conf.BetaBindPort), - Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta), - ReadTimeout: web.conf.ReadTimeout, - ReadHeaderTimeout: web.conf.ReadHeaderTimeout, - WriteTimeout: web.conf.WriteTimeout, - } - go func() { - betaErr := web.httpServerBeta.ListenAndServe() - if betaErr != nil { - log.Error("starting beta http server: %s", betaErr) - } - }() - } + web.startBetaServer(hostStr) err := <-errs - if err != http.ErrServerClosed { + if !errors.Is(err, http.ErrServerClosed) { cleanupAlways() log.Fatal(err) } - // We use ErrServerClosed as a sign that we need to rebind on new address, so go back to the start of the loop + + // We use ErrServerClosed as a sign that we need to rebind on a new + // address, so go back to the start of the loop. } } +// startBetaServer starts the beta HTTP server if necessary. +func (web *Web) startBetaServer(hostStr string) { + if web.conf.BetaBindPort == 0 { + return + } + + web.httpServerBeta = &http.Server{ + ErrorLog: log.StdLog("web: plain: beta", log.DEBUG), + Addr: netutil.JoinHostPort(hostStr, web.conf.BetaBindPort), + Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta), + ReadTimeout: web.conf.ReadTimeout, + ReadHeaderTimeout: web.conf.ReadHeaderTimeout, + WriteTimeout: web.conf.WriteTimeout, + } + go func() { + defer log.OnPanic("web: plain: beta") + + betaErr := web.httpServerBeta.ListenAndServe() + if betaErr != nil && !errors.Is(betaErr, http.ErrServerClosed) { + log.Error("starting beta http server: %s", betaErr) + } + }() +} + // Close gracefully shuts down the HTTP servers. func (web *Web) Close(ctx context.Context) { log.Info("stopping http server...")