diff --git a/agent/dns.go b/agent/dns.go index 73d6a30a00..2b1845b549 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -732,8 +732,12 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) { // Beyond 2500 records, performance gets bad // Limit the number of records at once, anyway, it won't fit in 64k // For SRV Records, the max is around 500 records, for A, less than 2k - if len(resp.Answer) > 2048 { - resp.Answer = resp.Answer[:2048] + truncateAt := 2048 + if req.Question[0].Qtype == dns.TypeSRV { + truncateAt = 640 + } + if len(resp.Answer) > truncateAt { + resp.Answer = resp.Answer[:truncateAt] } if hasExtra { index = make(map[string]dns.RR, len(resp.Extra)) diff --git a/agent/dns_test.go b/agent/dns_test.go index 06216759d2..8de2396988 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -2818,9 +2818,9 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) { // Check for the truncate bit shouldBeTruncated := numServices > 4095 - if shouldBeTruncated != in.Truncated { - info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) in %v", - service, question, protocol, numServices, out) + if shouldBeTruncated != in.Truncated || len(in.Answer) > 2000 || len(in.Answer) < 1 || in.Len() > 65535 { + info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v", + service, question, protocol, numServices, len(in.Answer), out) t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info) } })