Skip to content

Commit

Permalink
Merge pull request #62 from storageos/bugfix/healthcheck-startup-edge…
Browse files Browse the repository at this point in the history
…case

Fix edgecase of healthcheck during api startup
  • Loading branch information
JoeReid authored Feb 14, 2019
2 parents bf45d0f + f9e2df6 commit 9358f09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ type doOptions struct {
forceJSON bool
force bool
unversioned bool

retryOn []int // http.status codes
}

func (c *Client) do(method, urlpath string, doOptions doOptions) (*http.Response, error) {
Expand Down Expand Up @@ -338,6 +340,7 @@ func (c *Client) do(method, urlpath string, doOptions doOptions) (*http.Response

resp, err := httpClient.Do(req.WithContext(ctx))
if err != nil {

// If it is a custom error, return it. It probably knows more than us
if serror.IsStorageOSError(err) {
switch serror.ErrorKind(err) {
Expand Down Expand Up @@ -366,6 +369,17 @@ func (c *Client) do(method, urlpath string, doOptions doOptions) (*http.Response
}
}

var shouldretry bool
if doOptions.retryOn != nil {
for _, code := range doOptions.retryOn {
if resp.StatusCode == code {
failedAddresses[address] = struct{}{}
shouldretry = true
}

}
}

// If we get to the point of response, we should move any failed
// addresses to the back.
failed := len(failedAddresses)
Expand All @@ -388,6 +402,10 @@ func (c *Client) do(method, urlpath string, doOptions doOptions) (*http.Response
c.addressLock.Unlock()
}

if shouldretry {
continue
}

if resp.StatusCode < 200 || resp.StatusCode >= 400 {
return nil, newError(resp) // These status codes are likely to be fatal
}
Expand Down
2 changes: 1 addition & 1 deletion health.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (c *Client) ClusterHealth(ctx context.Context) ([]*types.ClusterHealthNode,
status := []*types.ClusterHealthNode{}
url := fmt.Sprintf("/cluster/%s", HealthAPIPrefix)

resp, err := c.do("GET", url, doOptions{context: ctx})
resp, err := c.do("GET", url, doOptions{context: ctx, retryOn: []int{http.StatusNotFound}})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9358f09

Please sign in to comment.