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:
parent
fd705b4783
commit
d31b118978
2 changed files with 56 additions and 10 deletions
31
plugin/transfer/failed_write_test.go
Normal file
31
plugin/transfer/failed_write_test.go
Normal 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")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue