fix locking around ssh tunnels

This commit is contained in:
Daniel Smith
2015-06-18 16:31:54 -07:00
parent 847d771198
commit 4126622388
2 changed files with 36 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/http"
"net/http/pprof"
@@ -774,9 +775,23 @@ func findExternalAddress(node *api.Node) (string, error) {
}
func (m *Master) Dial(net, addr string) (net.Conn, error) {
m.tunnelsLock.Lock()
defer m.tunnelsLock.Unlock()
return m.tunnels.Dial(net, addr)
// Only lock while picking a tunnel.
tunnel, err := func() (util.SSHTunnelEntry, error) {
m.tunnelsLock.Lock()
defer m.tunnelsLock.Unlock()
return m.tunnels.PickRandomTunnel()
}()
if err != nil {
return nil, err
}
start := time.Now()
id := rand.Int63() // So you can match begins/ends in the log.
glog.V(3).Infof("[%x: %v] Dialing...", id, tunnel.Address)
defer func() {
glog.V(3).Infof("[%x: %v] Dialed in %v.", id, tunnel.Address, time.Now().Sub(start))
}()
return tunnel.Tunnel.Dial(net, addr)
}
func (m *Master) needToReplaceTunnels(addrs []string) bool {