plugin/proxy: return client error (#1646)

Return the client error if there was one instead of the generic
"no healthy upstream or error"
This commit is contained in:
Miek Gieben 2018-04-01 14:23:40 +01:00 committed by GitHub
parent 2338120f5b
commit 5f98e98107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -65,6 +65,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
fails := 0
var span, child ot.Span
var upstreamErr error
span = ot.SpanFromContext(ctx)
for _, proxy := range f.list() {
@ -93,6 +94,7 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
}
ret, err = truncated(ret, err)
upstreamErr = err
if err != nil {
// Kick off health check to see if *our* upstream is broken.
@ -124,6 +126,10 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
return 0, nil
}
if upstreamErr != nil {
return dns.RcodeServerFailure, upstreamErr
}
return dns.RcodeServerFailure, errNoHealthy
}
@ -155,7 +161,7 @@ func (f *Forward) list() []*Proxy { return f.p.List(f.proxies) }
var (
errInvalidDomain = errors.New("invalid domain for forward")
errNoHealthy = errors.New("no healthy proxies or upstream error")
errNoHealthy = errors.New("no healthy proxies")
errNoForward = errors.New("no forwarder defined")
)