Skip to content

Commit 5cac9c0

Browse files
committed
Add timeout and retries for open wisdom
1 parent 19ef593 commit 5cac9c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

wisdom/wisdom.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"net/url"
1212
"strconv"
13+
"time"
1314

1415
"github.com/pkg/errors"
1516
)
@@ -54,7 +55,17 @@ func (h *WisdomHosts) Hosts(scope string, size int) ([]string, error) {
5455
reqURL.Query().Set("family", h.Family)
5556
}
5657

57-
resp, err := http.Get(reqURL.String())
58+
client := &http.Client{
59+
Timeout: 5 * time.Second,
60+
}
61+
62+
var resp *http.Response
63+
for n := 0; n < 3; n++ {
64+
resp, err = client.Get(reqURL.String())
65+
if err == nil {
66+
break
67+
}
68+
}
5869
if err != nil {
5970
return nil, err
6071
}

0 commit comments

Comments
 (0)