mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 02:03:13 -05:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user