Commit ebd3742e authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

communicator/ssh: retry connection in ConnectFunc forawhile

parent 2fff555e
package ssh
import (
"errors"
"log"
"net"
"time"
......@@ -11,7 +12,22 @@ import (
// is suitable for use with the SSH communicator configuration.
func ConnectFunc(network, addr string) func() (net.Conn, error) {
return func() (net.Conn, error) {
log.Printf("Opening conn for SSH to %s %s", network, addr)
return net.DialTimeout(network, addr, 15*time.Second)
timeout := time.After(5 * time.Minute)
for {
select {
case <-timeout:
return nil, errors.New("timeout connecting to remote machine")
default:
}
log.Printf("Opening conn for SSH to %s %s", network, addr)
nc, err := net.DialTimeout(network, addr, 15*time.Second)
if err == nil {
return nc, nil
}
time.Sleep(500 * time.Millisecond)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment