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>
This commit is contained in:
Miek Gieben
2018-10-23 20:19:36 +01:00
committed by GitHub
parent 22bffa7282
commit e8e8187a64
2 changed files with 9 additions and 13 deletions

View File

@@ -31,7 +31,7 @@ godeps:
go get -u github.com/prometheus/client_golang/prometheus/promhttp go get -u github.com/prometheus/client_golang/prometheus/promhttp
go get -u github.com/prometheus/client_golang/prometheus 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/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) (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 @ # 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 go get -u golang.org/x/tools/cmd/benchcmp || true

View File

@@ -120,22 +120,18 @@ func (s *serialErr) Error() string {
// If serial >= 0 it will reload the zone, if the SOA hasn't changed // If serial >= 0 it will reload the zone, if the SOA hasn't changed
// it returns an error indicating nothing was read. // it returns an error indicating nothing was read.
func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error) { func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error) {
tokens := dns.ParseZone(f, dns.Fqdn(origin), fileName)
defer func() { zp := dns.NewZoneParser(f, dns.Fqdn(origin), fileName)
// Drain the tokens chan so that large zone files won't zp.SetIncludeAllowed(true)
// leak goroutines and memory.
for range tokens {
}
}()
z := NewZone(origin, fileName) z := NewZone(origin, fileName)
seenSOA := false seenSOA := false
for x := range tokens { for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
if x.Error != nil { if err := zp.Err(); err != nil {
return nil, x.Error return nil, err
} }
if !seenSOA && serial >= 0 { 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 if s.Serial == uint32(serial) { // same serial
return nil, &serialErr{err: "no change in SOA serial", origin: origin, zone: fileName, serial: 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 return nil, err
} }
} }