Skip to content

Commit 6840d8c

Browse files
committed
update.
1 parent 3fb0b11 commit 6840d8c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

connect.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ func (c *Connect) CreateClient(host, port, user string, authMethods []ssh.AuthMe
117117
uri := net.JoinHostPort(host, port)
118118

119119
timeout := 20
120-
if c.ConnectTimeout > 0 {
121-
timeout = c.ConnectTimeout
120+
if c.ConnectTimeout == 0 {
121+
c.ConnectTimeout = timeout
122122
}
123123

124124
// Create new ssh.ClientConfig{}
125125
config := &ssh.ClientConfig{
126126
User: user,
127127
Auth: authMethods,
128-
Timeout: time.Duration(timeout) * time.Second,
128+
Timeout: time.Duration(c.ConnectTimeout) * time.Second,
129129
}
130130

131131
if c.HostKeyCallback != nil {
@@ -147,7 +147,7 @@ func (c *Connect) CreateClient(host, port, user string, authMethods []ssh.AuthMe
147147
c.ProxyDialer = proxy.Direct
148148
}
149149

150-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
150+
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.ConnectTimeout)*time.Second)
151151
defer cancel()
152152

153153
// Dial to host:port
@@ -157,7 +157,7 @@ func (c *Connect) CreateClient(host, port, user string, authMethods []ssh.AuthMe
157157
}
158158

159159
// Set deadline
160-
netConn.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
160+
netConn.SetDeadline(time.Now().Add(time.Duration(c.ConnectTimeout) * time.Second))
161161

162162
// Create new ssh connect
163163
sshCon, channel, req, cerr := ssh.NewClientConn(netConn, uri, config)

0 commit comments

Comments
 (0)