From cf175b4733cd938c1994230b91331faecf2d24fd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Aug 2013 11:53:31 -0700 Subject: [PATCH] communicator/ssh: respect interrupts by not looping on retyr [GH-327] --- CHANGELOG.md | 1 + common/step_connect_ssh.go | 2 +- communicator/ssh/connect.go | 22 +++------------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bec14aa..c999a9b73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ BUG FIXES: +* core: Fixed a couple cases where a double ctrl-C could panic. * command/build,command/validate: If a non-existent build is specified to '-only' or '-except', it is now an error. [GH-326] diff --git a/common/step_connect_ssh.go b/common/step_connect_ssh.go index c6e878367..b30969852 100644 --- a/common/step_connect_ssh.go +++ b/common/step_connect_ssh.go @@ -116,7 +116,7 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}, cancel <-chan } // Attempt to connect to SSH port - connFunc := ssh.ConnectFunc("tcp", address, 5*time.Minute) + connFunc := ssh.ConnectFunc("tcp", address) nc, err := connFunc() if err != nil { log.Printf("TCP connection to SSH ip/port failed: %s", err) diff --git a/communicator/ssh/connect.go b/communicator/ssh/connect.go index 071e3c40d..3ea91ce97 100644 --- a/communicator/ssh/connect.go +++ b/communicator/ssh/connect.go @@ -1,7 +1,6 @@ package ssh import ( - "errors" "log" "net" "time" @@ -10,24 +9,9 @@ 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, timeout time.Duration) func() (net.Conn, error) { +func ConnectFunc(network, addr string) func() (net.Conn, error) { return func() (net.Conn, error) { - timeoutCh := time.After(timeout) - - for { - select { - case <-timeoutCh: - 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) - } + log.Printf("Opening conn for SSH to %s %s", network, addr) + return net.DialTimeout(network, addr, 15*time.Second) } }