plugin/transfer: fix go-routine leak (#4380)

PR #4161 is stalled. Tried to cherry pick the code from there, but that
led to conflicts, manually copying over while taking into account the
comments on that PR. Use that code and extend the error checking, don't
modify existing tests and make the badwriter test simpler.

Closes: #4161

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

add tests

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2021-01-13 09:16:01 +01:00 committed by GitHub
parent fd705b4783
commit d31b118978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 10 deletions

View file

@ -0,0 +1,31 @@
package transfer
import (
"context"
"fmt"
"testing"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
)
type badwriter struct {
dns.ResponseWriter
count int
}
func (w *badwriter) WriteMsg(res *dns.Msg) error { return fmt.Errorf("failed to write msg") }
func TestWriteMessageFailed(t *testing.T) {
transfer := newTestTransfer()
ctx := context.TODO()
w := &badwriter{ResponseWriter: &test.ResponseWriter{}}
m := &dns.Msg{}
m.SetAxfr("example.org.")
_, err := transfer.ServeDNS(ctx, w, m)
if err == nil {
t.Error("Expected error, got none")
}
}