Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(godday): panic when retryAfter is 0 #4873

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions provider/godaddy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,16 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
resp, err := c.Client.Do(req)
// In case of several clients behind NAT we still can hit rate limit
for i := 1; i < 3 && err == nil && resp.StatusCode == 429; i++ {
retryAfter, _ := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0)

jitter := rand.Int63n(retryAfter)
var retryAfter int64
var jitter int64
if headerValue := resp.Header.Get("Retry-After"); headerValue == "" {
retryAfter = 30
} else {
retryAfter, _ = strconv.ParseInt(headerValue, 10, 0)
if retryAfter > 0 {
jitter = rand.Int63n(retryAfter)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In go, developers prefer readability.
Would you please rewrite this code with this pesudo pattern:

retryAfter = 30
receivedValue := resp.Header.Get("Retry-After")
if receivedValue != "" {
  // [...]
  retryAfter = somethingElse
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your review, I modified the code and made it more concise while maintaining the default value of 30. thank you!

retryAfterSec := retryAfter + jitter/2

sleepTime := time.Duration(retryAfterSec) * time.Second
Expand Down Expand Up @@ -344,4 +351,4 @@ func (c *Client) validate() error {
}

return nil
}
}