aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-04-24 17:09:15 +0100
committerGravatar GitHub <noreply@github.com> 2018-04-24 17:09:15 +0100
commitf529a2771ff9d1be38d2200c0e02382600b499f1 (patch)
tree84b877da3539c7684febf216339dbf7b81d0eb7a /plugin
parentd49194623f3b87701efd4d636b4a8caaec3b51aa (diff)
downloadcoredns-f529a2771ff9d1be38d2200c0e02382600b499f1.tar.gz
coredns-f529a2771ff9d1be38d2200c0e02382600b499f1.tar.zst
coredns-f529a2771ff9d1be38d2200c0e02382600b499f1.zip
plugin/forward: close channels when connManager returns (#1727)
Close a bunch of channels, also change the test to just use a for loop with a counter.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/forward/persistent.go9
-rw-r--r--plugin/forward/proxy_test.go4
2 files changed, 9 insertions, 4 deletions
diff --git a/plugin/forward/persistent.go b/plugin/forward/persistent.go
index 2f488e485..decac412c 100644
--- a/plugin/forward/persistent.go
+++ b/plugin/forward/persistent.go
@@ -44,7 +44,14 @@ func newTransport(addr string, tlsConfig *tls.Config) *transport {
ret: make(chan connErr),
stop: make(chan bool),
}
- go t.connManager()
+ go func() {
+ t.connManager()
+ // if connManager returns it has been stopped.
+ close(t.stop)
+ close(t.yield)
+ close(t.dial)
+ // close(t.ret) // we can still be dialing and wanting to send back the socket on t.ret
+ }()
return t
}
diff --git a/plugin/forward/proxy_test.go b/plugin/forward/proxy_test.go
index 8c53f3150..e33e274c0 100644
--- a/plugin/forward/proxy_test.go
+++ b/plugin/forward/proxy_test.go
@@ -25,9 +25,7 @@ func TestProxyClose(t *testing.T) {
state := request.Request{W: &test.ResponseWriter{}, Req: req}
ctx := context.TODO()
- repeatCnt := 1000
- for repeatCnt > 0 {
- repeatCnt--
+ for i := 0; i < 100; i++ {
p := NewProxy(s.Addr, nil /* no TLS */)
p.start(hcDuration)