aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-10-23 20:19:36 +0100
committerGravatar GitHub <noreply@github.com> 2018-10-23 20:19:36 +0100
commite8e8187a648543a50213f50d74baa4a6cc51188e (patch)
tree8b8ac2187bced88534fc18ed769e78237d6630f9
parent22bffa72822e812247b1f66453f7a37cc5f22443 (diff)
downloadcoredns-e8e8187a648543a50213f50d74baa4a6cc51188e.tar.gz
coredns-e8e8187a648543a50213f50d74baa4a6cc51188e.tar.zst
coredns-e8e8187a648543a50213f50d74baa4a6cc51188e.zip
plugin/file: Use new zone parser API (#2219)
* plugin/file: Use new zone parser API Use new dns lib 1.0.14 and default to using the new zone parser that does not leak go-routines. Signed-off-by: Miek Gieben <miek@miek.nl> * Use new API Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r--Makefile2
-rw-r--r--plugin/file/file.go20
2 files changed, 9 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index d37c77c76..ea883405c 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ godeps:
go get -u github.com/prometheus/client_golang/prometheus/promhttp
go get -u github.com/prometheus/client_golang/prometheus
(cd $(GOPATH)/src/github.com/mholt/caddy && git checkout -q v0.10.13)
- (cd $(GOPATH)/src/github.com/miekg/dns && git checkout -q v1.0.12)
+ (cd $(GOPATH)/src/github.com/miekg/dns && git checkout -q v1.0.14)
(cd $(GOPATH)/src/github.com/prometheus/client_golang && git checkout -q v0.8.0)
@ # for travis only, if this fails we don't care, but don't see benchmarks
go get -u golang.org/x/tools/cmd/benchcmp || true
diff --git a/plugin/file/file.go b/plugin/file/file.go
index 2711282eb..ee4d64da0 100644
--- a/plugin/file/file.go
+++ b/plugin/file/file.go
@@ -120,22 +120,18 @@ func (s *serialErr) Error() string {
// If serial >= 0 it will reload the zone, if the SOA hasn't changed
// it returns an error indicating nothing was read.
func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error) {
- tokens := dns.ParseZone(f, dns.Fqdn(origin), fileName)
- defer func() {
- // Drain the tokens chan so that large zone files won't
- // leak goroutines and memory.
- for range tokens {
- }
- }()
+
+ zp := dns.NewZoneParser(f, dns.Fqdn(origin), fileName)
+ zp.SetIncludeAllowed(true)
z := NewZone(origin, fileName)
seenSOA := false
- for x := range tokens {
- if x.Error != nil {
- return nil, x.Error
+ for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
+ if err := zp.Err(); err != nil {
+ return nil, err
}
if !seenSOA && serial >= 0 {
- if s, ok := x.RR.(*dns.SOA); ok {
+ if s, ok := rr.(*dns.SOA); ok {
if s.Serial == uint32(serial) { // same serial
return nil, &serialErr{err: "no change in SOA serial", origin: origin, zone: fileName, serial: serial}
}
@@ -143,7 +139,7 @@ func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error) {
}
}
- if err := z.Insert(x.RR); err != nil {
+ if err := z.Insert(rr); err != nil {
return nil, err
}
}