aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/file.go
diff options
context:
space:
mode:
authorGravatar Tom Thorogood <me+github@tomthorogood.co.uk> 2018-10-14 04:26:42 +1030
committerGravatar Miek Gieben <miek@miek.nl> 2018-10-13 18:56:42 +0100
commit1847ef6bd31ecd38fe5d19e54c47a812cb2ed303 (patch)
tree5d5dc3cfba918f34d62317e492484183590a14e2 /plugin/file/file.go
parent3cef6674e93d7287f245c97ab525ca0ea915a5c6 (diff)
downloadcoredns-1847ef6bd31ecd38fe5d19e54c47a812cb2ed303.tar.gz
coredns-1847ef6bd31ecd38fe5d19e54c47a812cb2ed303.tar.zst
coredns-1847ef6bd31ecd38fe5d19e54c47a812cb2ed303.zip
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
Diffstat (limited to '')
-rw-r--r--plugin/file/file.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/plugin/file/file.go b/plugin/file/file.go
index 5c13042cb..2711282eb 100644
--- a/plugin/file/file.go
+++ b/plugin/file/file.go
@@ -121,6 +121,12 @@ func (s *serialErr) Error() string {
// 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 {
+ }
+ }()
z := NewZone(origin, fileName)
seenSOA := false
for x := range tokens {