communicator/ssh: respect interrupts by not looping on retyr [GH-327]
This commit is contained in:
parent
24b12993b7
commit
3375c9e4fd
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
BUG FIXES:
|
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
|
* command/build,command/validate: If a non-existent build is specified to
|
||||||
'-only' or '-except', it is now an error. [GH-326]
|
'-only' or '-except', it is now an error. [GH-326]
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}, cancel <-chan
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to connect to SSH port
|
// Attempt to connect to SSH port
|
||||||
connFunc := ssh.ConnectFunc("tcp", address, 5*time.Minute)
|
connFunc := ssh.ConnectFunc("tcp", address)
|
||||||
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)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -10,24 +9,9 @@ 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, timeout time.Duration) func() (net.Conn, error) {
|
func ConnectFunc(network, addr string) func() (net.Conn, error) {
|
||||||
return func() (net.Conn, error) {
|
return func() (net.Conn, error) {
|
||||||
timeoutCh := time.After(timeout)
|
log.Printf("Opening conn for SSH to %s %s", network, addr)
|
||||||
|
return net.DialTimeout(network, addr, 15*time.Second)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue