builder/virtualbox: time out on SSH handshake for retry

This commit is contained in:
Mitchell Hashimoto 2013-06-12 00:54:25 -07:00
parent 5c0d8ecd72
commit c58d5ab3af
2 changed files with 21 additions and 6 deletions

View File

@ -9,8 +9,8 @@ import (
func testConfig() map[string]interface{} {
return map[string]interface{}{
"iso_md5": "foo",
"iso_url": "http://www.google.com/",
"iso_md5": "foo",
"iso_url": "http://www.google.com/",
"ssh_username": "foo",
}
}

View File

@ -115,10 +115,25 @@ func (s *stepWaitForSSH) waitForSSH(state map[string]interface{}) (packer.Commun
},
}
comm, err = ssh.New(nc, sshConfig)
if err != nil {
log.Printf("SSH connection fail: %s", err)
nc.Close()
sshConnectSuccess := make(chan bool, 1)
go func() {
comm, err = ssh.New(nc, sshConfig)
if err != nil {
log.Printf("SSH connection fail: %s", err)
sshConnectSuccess <- false
return
}
sshConnectSuccess <- true
}()
select {
case success := <-sshConnectSuccess:
if !success {
continue
}
case <-time.After(5 * time.Second):
log.Printf("SSH handshake timeout. Trying again.")
continue
}