Skip to content

Commit

Permalink
Pull request: proxy: imp timeout logs
Browse files Browse the repository at this point in the history
Updates AdguardTeam/AdGuardHome#4128.

Squashed commit of the following:

commit 9211b05
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Feb 15 16:28:23 2022 +0300

    proxy: imp timeout logs
  • Loading branch information
ainar-g committed Feb 15, 2022
1 parent 5956b6d commit 99558ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"time"

"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
)
Expand Down Expand Up @@ -166,19 +165,10 @@ func (p *Proxy) respond(d *DNSContext) {
}

if err != nil {
if isNonCriticalError(err) {
// We're probably restarting, so log this with the debug level.
log.Debug("responding to %s request: %s", d.Proto, err)
} else {
log.Info("responding to %s request: %s", d.Proto, err)
}
logWithNonCrit(err, fmt.Sprintf("responding %s request", d.Proto))
}
}

func isNonCriticalError(err error) (ok bool) {
return isEPIPE(err) || errors.Is(err, net.ErrClosed)
}

// Set TTL value of all records according to our settings
func (p *Proxy) setMinMaxTTL(r *dns.Msg) {
for _, rr := range r.Answer {
Expand Down
4 changes: 2 additions & 2 deletions proxy/server_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func (p *Proxy) handleTCPConnection(conn net.Conn, proto Proto) {

err = p.handleDNSRequest(d)
if err != nil {
log.Error("handling tcp: handling %s request: %s", d.Proto, err)
logWithNonCrit(err, fmt.Sprintf("handling tcp: handling %s request", d.Proto))
}
}
}

// logWithNonCrit logs the error on the appropriate level depending on whether
// err is a critical error or not.
func logWithNonCrit(err error, msg string) {
if errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) {
if errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) || isEPIPE(err) {
log.Debug("%s: connection is closed; original error: %s", msg, err)
} else if netErr := net.Error(nil); errors.As(err, &netErr) && netErr.Timeout() {
log.Debug("%s: connection timed out; original error: %s", msg, err)
Expand Down

0 comments on commit 99558ce

Please sign in to comment.