Skip to content

Commit 7ae03e5

Browse files
authored
Merge pull request #38 from gruntwork-io/ssh-timeout
Set connection timeouts
2 parents 782c2e3 + 8952079 commit 7ae03e5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

http/http_helper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import (
1313
func HttpGet(url string, logger *log.Logger) (int, string, error) {
1414
logger.Println("Making an HTTP GET call to URL", url)
1515

16-
resp, err := http.Get(url)
16+
client := http.Client{
17+
// By default, Go does not impose a timeout, so an HTTP connection attempt can hang for a LONG time.
18+
Timeout: 10 * time.Second,
19+
}
20+
21+
resp, err := client.Get(url)
1722
if err != nil {
1823
return -1, "", err
1924
}

ssh/ssh.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"golang.org/x/crypto/ssh"
77
"net"
8+
"time"
89
)
910

1011
type Host struct {
@@ -166,6 +167,8 @@ func createSshClientConfig(hostOptions *SshConnectionOptions) *ssh.ClientConfig
166167
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
167168
return nil
168169
},
170+
// By default, Go does not impose a timeout, so a SSH connection attempt can hang for a LONG time.
171+
Timeout: 10 * time.Second,
169172
}
170173
clientConfig.SetDefaults()
171174
return clientConfig

0 commit comments

Comments
 (0)