aboutsummaryrefslogtreecommitdiff
path: root/plugin/proxy/grpc.go
diff options
context:
space:
mode:
authorGravatar Francois Tur <ftur@infoblox.com> 2018-02-14 14:20:27 -0500
committerGravatar Miek Gieben <miek@miek.nl> 2018-02-14 20:20:27 +0100
commitee8084a08f8cfcd4357ae2ad0b6dff51ca322d3a (patch)
tree45c51f60e3c6e246936af52b0663a2208df7cea9 /plugin/proxy/grpc.go
parent76455c6a0deb812db4a6a091cdf305ef4960c5b7 (diff)
downloadcoredns-ee8084a08f8cfcd4357ae2ad0b6dff51ca322d3a.tar.gz
coredns-ee8084a08f8cfcd4357ae2ad0b6dff51ca322d3a.tar.zst
coredns-ee8084a08f8cfcd4357ae2ad0b6dff51ca322d3a.zip
Plugin/Proxy - prevent nil pointer when query using a gRPC client that could not dial in (#1495)
* prevent nil pointer when query frpc client that could not open * add UT checking we can now safely request DNS query on an invalid hostname, query for gRPC connection * fix ortograph * fix format * fix package declaration, fix UT - grpclogger, use fatalf, build pool with known addresses * type, useless error check - after review
Diffstat (limited to 'plugin/proxy/grpc.go')
-rw-r--r--plugin/proxy/grpc.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/plugin/proxy/grpc.go b/plugin/proxy/grpc.go
index b1ac1b1a8..2844a1c71 100644
--- a/plugin/proxy/grpc.go
+++ b/plugin/proxy/grpc.go
@@ -2,6 +2,7 @@ package proxy
import (
"crypto/tls"
+ "fmt"
"log"
"github.com/coredns/coredns/pb"
@@ -42,16 +43,19 @@ func (g *grpcClient) Exchange(ctx context.Context, addr string, state request.Re
return nil, err
}
- reply, err := g.clients[addr].Query(ctx, &pb.DnsPacket{Msg: msg})
- if err != nil {
- return nil, err
- }
- d := new(dns.Msg)
- err = d.Unpack(reply.Msg)
- if err != nil {
- return nil, err
+ if cl, ok := g.clients[addr]; ok {
+ reply, err := cl.Query(ctx, &pb.DnsPacket{Msg: msg})
+ if err != nil {
+ return nil, err
+ }
+ d := new(dns.Msg)
+ err = d.Unpack(reply.Msg)
+ if err != nil {
+ return nil, err
+ }
+ return d, nil
}
- return d, nil
+ return nil, fmt.Errorf("grpc exchange - no connection available for host: %s ", addr)
}
func (g *grpcClient) Transport() string { return "tcp" }