Commit 0ca03f09 authored by Chris Bednarski's avatar Chris Bednarski

Fix some style issues and add a doc to ErrHandshakeTimeout

parent 5dd8ae45
...@@ -20,6 +20,9 @@ import ( ...@@ -20,6 +20,9 @@ import (
"golang.org/x/crypto/ssh/agent" "golang.org/x/crypto/ssh/agent"
) )
// ErrHandshakeTimeout is returned from New() whenever we're unable to establish
// an ssh connection within a certain timeframe. By default the handshake time-
// out period is 1 minute. You can change it with Config.HandshakeTimeout.
var ErrHandshakeTimeout = fmt.Errorf("Timeout during SSH handshake") var ErrHandshakeTimeout = fmt.Errorf("Timeout during SSH handshake")
type comm struct { type comm struct {
...@@ -291,8 +294,7 @@ func (c *comm) reconnect() (err error) { ...@@ -291,8 +294,7 @@ func (c *comm) reconnect() (err error) {
duration = c.config.HandshakeTimeout duration = c.config.HandshakeTimeout
} }
timeoutExceeded := time.After(duration) connectionEstablished := make(chan struct{}, 1)
connectionEstablished := make(chan bool, 1)
var sshConn ssh.Conn var sshConn ssh.Conn
var sshChan <-chan ssh.NewChannel var sshChan <-chan ssh.NewChannel
...@@ -300,14 +302,14 @@ func (c *comm) reconnect() (err error) { ...@@ -300,14 +302,14 @@ func (c *comm) reconnect() (err error) {
go func() { go func() {
sshConn, sshChan, req, err = ssh.NewClientConn(c.conn, c.address, c.config.SSHConfig) sshConn, sshChan, req, err = ssh.NewClientConn(c.conn, c.address, c.config.SSHConfig)
connectionEstablished <- true close(connectionEstablished)
}() }()
select { select {
case <-connectionEstablished: case <-connectionEstablished:
// We don't need to do anything here. We just want select to block until // We don't need to do anything here. We just want select to block until
// we connect or timeout. // we connect or timeout.
case <-timeoutExceeded: case <-time.After(duration):
if c.conn != nil { if c.conn != nil {
c.conn.Close() c.conn.Close()
} }
......
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