aboutsummaryrefslogtreecommitdiff
path: root/plugin/grpc/grpc.go
diff options
context:
space:
mode:
authorGravatar Ricardo Katz <rikatz@users.noreply.github.com> 2020-07-15 14:59:45 -0300
committerGravatar GitHub <noreply@github.com> 2020-07-15 19:59:45 +0200
commit3ebb46320a4b47af1405bd413dee9c8937dfd88c (patch)
tree8d4de96a47e748d230f4eacecbf6732761da965d /plugin/grpc/grpc.go
parentd37173814913aa7488951d4a4f256a8662c3c45e (diff)
downloadcoredns-3ebb46320a4b47af1405bd413dee9c8937dfd88c.tar.gz
coredns-3ebb46320a4b47af1405bd413dee9c8937dfd88c.tar.zst
coredns-3ebb46320a4b47af1405bd413dee9c8937dfd88c.zip
Improve gRPC Plugin when backend is not available (#3966)
* Improve gRPC Plugin when backend is not available Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@serpro.gov.br> * Improve gRPC Plugin when backend is not available Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@serpro.gov.br>
Diffstat (limited to 'plugin/grpc/grpc.go')
-rw-r--r--plugin/grpc/grpc.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/plugin/grpc/grpc.go b/plugin/grpc/grpc.go
index 3dda225df..2ecf29597 100644
--- a/plugin/grpc/grpc.go
+++ b/plugin/grpc/grpc.go
@@ -3,6 +3,7 @@ package grpc
import (
"context"
"crypto/tls"
+ "errors"
"time"
"github.com/coredns/coredns/plugin"
@@ -36,10 +37,10 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
}
var (
- span, child ot.Span
- ret *dns.Msg
- err error
- i int
+ span, child ot.Span
+ ret *dns.Msg
+ upstreamErr, err error
+ i int
)
span = ot.SpanFromContext(ctx)
list := g.list()
@@ -73,6 +74,8 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
child.Finish()
}
+ upstreamErr = err
+
// Check if the reply is correct; if not return FormErr.
if !state.Match(ret) {
debug.Hexdumpf(ret, "Wrong reply for id: %d, %s %d", ret.Id, state.QName(), state.QType())
@@ -87,7 +90,11 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
return 0, nil
}
- return 0, nil
+ if upstreamErr != nil {
+ return dns.RcodeServerFailure, upstreamErr
+ }
+
+ return dns.RcodeServerFailure, ErrNoHealthy
}
// NewGRPC returns a new GRPC.
@@ -129,3 +136,8 @@ func (g *GRPC) isAllowedDomain(name string) bool {
func (g *GRPC) list() []*Proxy { return g.p.List(g.proxies) }
const defaultTimeout = 5 * time.Second
+
+var (
+ // ErrNoHealthy means no healthy proxies left.
+ ErrNoHealthy = errors.New("no healthy gRPC proxies")
+)