Commit 1847ef6b authored by Tom Thorogood's avatar Tom Thorogood Committed by Miek Gieben

plugin/file: Fix memory leak in Parse (#2194)

For zone files with more than 10,000 records, the goroutines and memory
pinned by dns.ParseZone won't be released unless the tokens chan is
drained. As Parse is called by (*Zone).Reload very frequently, this
causes memory leaks and OOM conditions.

Updates miekg/dns#786
parent 3cef6674
...@@ -121,6 +121,12 @@ func (s *serialErr) Error() string { ...@@ -121,6 +121,12 @@ func (s *serialErr) Error() string {
// 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) 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 {
}
}()
z := NewZone(origin, fileName) z := NewZone(origin, fileName)
seenSOA := false seenSOA := false
for x := range tokens { for x := range tokens {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment