-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: master
Are you sure you want to change the base?
fix(godday): panic when retryAfter is 0 #4873
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @rayshoo! |
Hi @rayshoo. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Thanks for this PR. |
/retitle fix(godday): panic when retryAfter is 0 |
Fixes #4864 |
Is it correct to add the test code to the |
Yes it is.
This step is clearly mandatory. It's not that difficult, you will see :). |
provider/godaddy/client.go
Outdated
if headerValue := resp.Header.Get("Retry-After"); headerValue == "" { | ||
retryAfter = 30 | ||
} else { | ||
retryAfter, _ = strconv.ParseInt(headerValue, 10, 0) | ||
if retryAfter > 0 { | ||
jitter = rand.Int63n(retryAfter) | ||
} | ||
} |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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!
1373bd2
to
67ff232
Compare
@mloiseleur As I wringing the test code, I took a closer look at the code as a whole. I realized that even if I take care to prevent an error from occurring in Client.Do, the status code value is 429, so the subsequent function, UnmarshalResponse, returns an error, which leads to log.Fatal(err) in the main function and terminates the server. Therefore, if I receive a 429 error within the client. // provider/godaddy/client.go:224
func (c *Client) Do(req *http.Request) (*http.Response, error) {
// [...]
resp, err := c.Client.Do(req)
/*
Before
for i := 1; i < 3 && err == nil && resp.StatusCode == 429; i++ {
*/
// After
for err == nil && resp.StatusCode == 429 {
// [...] Also, during this time, I think the readiness probe needs to be taken down to tell Kubernetes that the server is not ready. // somePackage/someFilename.go
var Ready bool = true
// provider/godaddy/client.go:224
func (c *Client) Do(req *http.Request) (*http.Response, error) {
for err == nil && resp.StatusCode == 429 {
somePackage.Ready = false
// [...]
}
somePackage.Ready = true
// main.go:447
func serveMetrics(address string) {
http.HandleFunc("/live", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
})
http.HandleFunc("/ready", func(w http.ResponseWriter, _ *http.Request) {
if somePackage.Ready {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
} else {
w.WriteHeader(http.StatusPreconditionRequired)
w.Write([]byte("NOT READY"))
}
})
} However, this level of code requires more modifications than initially thought, so I don't know if it is desirable. I wrote my opinion carefully. |
Hey @rayshoo @mloiseleur! I have another PR open to address this issue, with tests as well ;) Please let me know what you think: #4866 |
… process
Description
Handles panic when the retryAfter header is parsed as 0 or less or blank when responding 429 from GoDaddy API.
Fixes #ISSUE
This is a code fix for the issue #4864
Checklist