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.
This commit is contained in:
Miek Gieben 2018-04-24 17:09:15 +01:00 committed by GitHub
parent d49194623f
commit f529a2771f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -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
}

View file

@ -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)