Commit a0f1667d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

communicator/ssh: tweakable timeout on retry connection

parent ebd3742e
......@@ -87,7 +87,7 @@ func (s *stepConnectSSH) waitForSSH(state map[string]interface{}) (packer.Commun
// Create the function that will be used to create the connection
connFunc := ssh.ConnectFunc(
"tcp", fmt.Sprintf("%s:%d", instance.DNSName, config.SSHPort))
"tcp", fmt.Sprintf("%s:%d", instance.DNSName, config.SSHPort), 5*time.Minute)
ui.Say("Waiting for SSH to become available...")
var comm packer.Communicator
......
......@@ -32,7 +32,10 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
return multistep.ActionHalt
}
connFunc := ssh.ConnectFunc("tcp", fmt.Sprintf("%s:%d", ipAddress, config.SSHPort))
connFunc := ssh.ConnectFunc(
"tcp",
fmt.Sprintf("%s:%d", ipAddress, config.SSHPort),
5*time.Minute)
// Build the actual SSH client configuration
sshConfig := &ssh.Config{
......
......@@ -85,7 +85,8 @@ func (s *stepWaitForSSH) waitForSSH(state map[string]interface{}) (packer.Commun
ui := state["ui"].(packer.Ui)
sshHostPort := state["sshHostPort"].(uint)
connFunc := ssh.ConnectFunc("tcp", fmt.Sprintf("127.0.0.1:%d", sshHostPort))
connFunc := ssh.ConnectFunc(
"tcp", fmt.Sprintf("127.0.0.1:%d", sshHostPort), 5*time.Minute)
ui.Say("Waiting for SSH to become available...")
var comm packer.Communicator
......
......@@ -141,7 +141,8 @@ func (s *stepWaitForSSH) waitForSSH(state map[string]interface{}) (packer.Commun
log.Printf("Detected IP: %s", ip)
// Attempt to connect to SSH port
connFunc := ssh.ConnectFunc("tcp", fmt.Sprintf("%s:%d", ip, config.SSHPort))
connFunc := ssh.ConnectFunc(
"tcp", fmt.Sprintf("%s:%d", ip, config.SSHPort), 5*time.Minute)
nc, err := connFunc()
if err != nil {
log.Printf("TCP connection to SSH ip/port failed: %s", err)
......
......@@ -10,13 +10,13 @@ import (
// ConnectFunc is a convenience method for returning a function
// that just uses net.Dial to communicate with the remote end that
// is suitable for use with the SSH communicator configuration.
func ConnectFunc(network, addr string) func() (net.Conn, error) {
func ConnectFunc(network, addr string, timeout time.Duration) func() (net.Conn, error) {
return func() (net.Conn, error) {
timeout := time.After(5 * time.Minute)
timeoutCh := time.After(timeout)
for {
select {
case <-timeout:
case <-timeoutCh:
return nil, errors.New("timeout connecting to remote machine")
default:
}
......
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