Skip to content

Commit

Permalink
Add timeout and retries for open wisdom
Browse files Browse the repository at this point in the history
  • Loading branch information
tg committed Sep 18, 2019
1 parent 19ef593 commit 5cac9c0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wisdom/wisdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"

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

resp, err := http.Get(reqURL.String())
client := &http.Client{
Timeout: 5 * time.Second,
}

var resp *http.Response
for n := 0; n < 3; n++ {
resp, err = client.Get(reqURL.String())
if err == nil {
break
}
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5cac9c0

Please sign in to comment.