file: close correctlty after AXFR (#2943)

* file: close correctlty after AXFR

Don't hijack, but wait for the writes to be done and then savely close
the connection.

Fixes: #2929

Signed-off-by: Miek Gieben <miek@miek.nl>

* Update comment

Signed-off-by: Miek Gieben <miek@miek.nl>

* file: close correctlty after AXFR (#2943)

apply

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2019-07-03 07:01:57 +01:00
committed by GitHub
parent f8bba51f84
commit 3e5fd21e68
2 changed files with 29 additions and 22 deletions

View File

@@ -3,6 +3,7 @@ package file
import (
"context"
"fmt"
"sync"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/request"
@@ -31,9 +32,13 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
}
ch := make(chan *dns.Envelope)
defer close(ch)
tr := new(dns.Transfer)
go tr.Out(w, r, ch)
wg := new(sync.WaitGroup)
go func() {
wg.Add(1)
tr.Out(w, r, ch)
wg.Done()
}()
j, l := 0, 0
records = append(records, records[0]) // add closing SOA to the end
@@ -49,9 +54,9 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
if j < len(records) {
ch <- &dns.Envelope{RR: records[j:]}
}
close(ch) // Even though we close the channel here, we still have
wg.Wait() // to wait before we can return and close the connection.
w.Hijack()
// w.Close() // Client closes connection
return dns.RcodeSuccess, nil
}