Merge pull request #3878 from hashicorp/issue-3877

Fixes a panic on TCP-based DNS lookups.
This commit is contained in:
James Phillips 2018-02-08 18:45:54 -08:00 committed by GitHub
commit 4f664595e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) { func TestDNS_NodeLookup(t *testing.T) {
t.Parallel() t.Parallel()
a := NewTestAgent(t.Name(), "") a := NewTestAgent(t.Name(), "")

View File

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