Fixes a panic on TCP-based DNS lookups.

This came in via the monkey patch in #3861.

Fixes #3877
This commit is contained in:
James Phillips 2018-02-08 17:57:41 -08:00
parent 94ea08d066
commit 3724e49ddf
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
2 changed files with 33 additions and 0 deletions

View File

@ -130,6 +130,38 @@ func TestEncodeKVasRFC1464(t *testing.T) {
}
}
func TestDNS_Over_TCP(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
// Register node
args := &structs.RegisterRequest{
Datacenter: "dc1",
Node: "Foo",
Address: "127.0.0.1",
}
var out struct{}
if err := a.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err)
}
m := new(dns.Msg)
m.SetQuestion("foo.node.dc1.consul.", dns.TypeANY)
c := new(dns.Client)
c.Net = "tcp"
in, _, err := c.Exchange(m, a.DNSAddr())
if err != nil {
t.Fatalf("err: %v", err)
}
if len(in.Answer) != 1 {
t.Fatalf("empty lookup: %#v", in)
}
}
func TestDNS_NodeLookup(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), "")

View File

@ -495,6 +495,7 @@ func (srv *Server) serveTCP(l net.Listener) error {
rw.Close()
return
}
srv.inFlight.Add(1)
srv.serve(rw.RemoteAddr(), handler, m, nil, nil, rw)
}()