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