From 1fdb3ee902082008f2d198783965bbf43b7070d0 Mon Sep 17 00:00:00 2001 From: CJ Cullen Date: Wed, 9 Nov 2016 14:07:19 -0800 Subject: [PATCH] Close tunnels after failed healthchecks. --- pkg/ssh/ssh.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/ssh/ssh.go b/pkg/ssh/ssh.go index f90afe263ce..c8469cc2a09 100644 --- a/pkg/ssh/ssh.go +++ b/pkg/ssh/ssh.go @@ -377,15 +377,18 @@ func (l *SSHTunnelList) healthCheck(e sshTunnelEntry) error { func (l *SSHTunnelList) removeAndReAdd(e sshTunnelEntry) { // Find the entry to replace. l.tunnelsLock.Lock() - defer l.tunnelsLock.Unlock() for i, entry := range l.entries { if entry.Tunnel == e.Tunnel { l.entries = append(l.entries[:i], l.entries[i+1:]...) l.adding[e.Address] = true - go l.createAndAddTunnel(e.Address) - return + break } } + l.tunnelsLock.Unlock() + if err := e.Tunnel.Close(); err != nil { + glog.Infof("Failed to close removed tunnel: %v", err) + } + go l.createAndAddTunnel(e.Address) } func (l *SSHTunnelList) Dial(net, addr string) (net.Conn, error) {